-
Notifications
You must be signed in to change notification settings - Fork 0
/
LogUtil.java
71 lines (51 loc) · 1.72 KB
/
LogUtil.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
61
62
63
64
65
66
67
68
69
70
71
package org.auioc.mcmod.arnicalib.base.log;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.Marker;
import org.apache.logging.log4j.MarkerManager;
public class LogUtil {
private LogUtil() {}
private static StackTraceElement getCaller() {
StackTraceElement[] callStack = Thread.currentThread().getStackTrace();
StackTraceElement caller = null;
String logClassName = LogUtil.class.getName();
int i = 0;
for (int len = callStack.length; i < len; i++) {
if (logClassName.equals(callStack[i].getClassName())) {
break;
}
}
caller = callStack[i + 3];
return caller;
}
public static Logger getLoggerByCaller() {
return LogManager.getLogger(getCaller().getClassName());
}
public static Logger getLogger(String name) {
return LogManager.getLogger(name);
}
public static Marker getMarker(String marker) {
return MarkerManager.getMarker(marker);
}
public static Marker getMarker(Class<?> clazz) {
return MarkerManager.getMarker(clazz.getSimpleName());
}
public static void trace(Object msg) {
getLoggerByCaller().trace(msg);
}
public static void debug(Object msg) {
getLoggerByCaller().debug(msg);
}
public static void info(Object msg) {
getLoggerByCaller().info(msg);
}
public static void warn(Object msg) {
getLoggerByCaller().warn(msg);
}
public static void error(Object msg) {
getLoggerByCaller().error(msg);
}
public static void error(Object msg, Throwable t) {
getLoggerByCaller().error(msg, t);
}
}