-
Notifications
You must be signed in to change notification settings - Fork 0
/
LogHelper.java
60 lines (42 loc) · 1.56 KB
/
LogHelper.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package kdx7214.necessities;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.google.common.base.Optional;
import cpw.mods.fml.common.FMLLog;
public enum LogHelper {
INSTANCE;
public static void fine(String format, Object... args) {
INSTANCE.log(Level.FINE, format, args);
}
public static void finer(String format, Object... args) {
INSTANCE.log(Level.FINER, format, args);
}
public static void finest(String format, Object... data) {
INSTANCE.log(Level.FINEST, format, data);
}
public static void info(String format, Object... args) {
INSTANCE.log(Level.INFO, format, args);
}
public static void log(Level level, Throwable exception, String format, Object... args) {
INSTANCE.getLogger().log(level, String.format(format, args), exception);
}
public static void severe(String format, Object... args) {
INSTANCE.log(Level.SEVERE, format, args);
}
public static void warning(String format, Object... args) {
INSTANCE.log(Level.WARNING, format, args);
}
private Optional<Logger> logger = Optional.absent();
private Logger getLogger() {
if (!logger.isPresent()) init();
return logger.get();
}
private void init() {
if (logger.isPresent()) return;
logger = Optional.of(Logger.getLogger("Necessities"));
logger.get().setParent(FMLLog.getLogger());
}
private void log(Level level, String format, Object... data) {
getLogger().log(level, String.format(format, data));
}
}