use global log level

This commit is contained in:
金戟 2020-12-04 22:50:02 +08:00
parent dd7499f3cf
commit 08aa73b4bd

View File

@ -8,28 +8,26 @@ public class LogUtil {
private static final int LEVEL_ERROR = 0; private static final int LEVEL_ERROR = 0;
private static final int LEVEL_WARN = 1; private static final int LEVEL_WARN = 1;
private static final int LEVEL_DIAGNOSE = 2; private static final int LEVEL_DIAGNOSE = 2;
private static final ThreadLocal<Integer> LEVEL = new ThreadLocal<Integer>(); private static int level;
public static boolean globalDebugEnable = false; public static boolean globalDebugEnable = false;
public static void debug(String msg, Object... args) { public static void debug(String msg, Object... args) {
if (LEVEL.get() >= LEVEL_DIAGNOSE) { if (level >= LEVEL_DIAGNOSE) {
System.out.println(String.format("[DIAGNOSE] " + msg, args)); System.out.println(String.format("[DIAGNOSE] " + msg, args));
} }
} }
public static void enableDebugLog() { public static void enableDebugLog() {
LEVEL.remove(); level = LEVEL_DIAGNOSE;
LEVEL.set(LEVEL_DIAGNOSE);
} }
public static void disableDebugLog() { public static void disableDebugLog() {
LEVEL.remove(); level = LEVEL_ERROR;
LEVEL.set(LEVEL_ERROR);
} }
public static void resetDebugLog() { public static void resetDebugLog() {
LEVEL.set(globalDebugEnable ? LEVEL_DIAGNOSE : LEVEL_WARN); level = globalDebugEnable ? LEVEL_DIAGNOSE : LEVEL_WARN;
} }
} }