-
Notifications
You must be signed in to change notification settings - Fork 4
/
MyLogger.java
34 lines (28 loc) · 901 Bytes
/
MyLogger.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import java.io.IOException;
import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;
class MyLogger {
private MyLogger() {
throw new IllegalStateException("Utility class");
}
private static final Logger log = Logger.getLogger("MyLogger");
static {
FileHandler fh;
try {
fh = new FileHandler("log.log", false);
log.addHandler(fh);
SimpleFormatter formatter = new SimpleFormatter();
fh.setFormatter(formatter);
} catch (IOException e) {
log.log(Level.SEVERE, e.getMessage());
}
}
public static void writeLog(String message) {
log.log(Level.INFO, message);
}
public static void writeLog(String message, Exception e) {
log.log(Level.WARNING, message, e);
}
}