Skip to content

Commit 19f4be5

Browse files
committed
feat: Enable logging with the singleton pattern
Resolves #4
1 parent 9508eff commit 19f4be5

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package de.uulm.sp.swt.profcalculator;
2+
3+
public class Logger {
4+
5+
private final static boolean LOGGING = true;
6+
7+
private static Logger logger = new Logger();
8+
9+
public Logger() {
10+
log("Logging enabled:");
11+
}
12+
13+
public static Logger getLogger() {
14+
return logger;
15+
}
16+
17+
public void log(String message) {
18+
if (LOGGING) {
19+
System.out.println(message);
20+
}
21+
}
22+
23+
}

ProfCalculator/src/de/uulm/sp/swt/profcalculator/ProfCalculator.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,11 @@ public void handle(ActionEvent event) {
5454
int newValue = Integer.parseInt(inputField.getText());
5555
if (event.getSource() == additionButton) {
5656
expression = new Addition(expression, new Value(newValue));
57+
Logger.getLogger().log("+ " + newValue);
5758
}
5859
else if (event.getSource() == multiplicationButton) {
5960
expression = new Multiplication(expression, new Value(newValue));
61+
Logger.getLogger().log("* " + newValue);
6062
}
6163
expression = new NecessaryBrackets(expression);
6264
updateGUI();

0 commit comments

Comments
 (0)