Skip to content

Commit ac58c7b

Browse files
committed
fix: Move logging level
1 parent 6bacc16 commit ac58c7b

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

src/main/java/com/github/exadmin/cyberferret/logging/HandyLogging.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,11 @@
55
import org.slf4j.LoggerFactory;
66

77
public class HandyLogging {
8-
private static final int LEVEL_ERROR = 0;
9-
private static final int LEVEL_WARN = 1;
10-
private static final int LEVEL_INFO = 2;
11-
private static final int LEVEL_DEBUG = 3;
12-
private static final int LEVEL_TRACE = 4;
8+
139

1410
protected volatile Logger logger;
1511
protected boolean printToConsole = false;
16-
protected final int loggingLevel = LEVEL_INFO;
12+
1713

1814
public void setPrintToConsole(boolean printToConsole) {
1915
this.printToConsole = printToConsole;
@@ -22,39 +18,39 @@ public void setPrintToConsole(boolean printToConsole) {
2218
public void logError(String msg, Object... binds) {
2319
if (getLogger() != null) {
2420
getLogger().error(msg, binds);
25-
} else if (loggingLevel >= LEVEL_ERROR) {
21+
} else {
2622
ConsoleUtils.error(msg, binds);
2723
}
2824
}
2925

3026
public void logWarn(String msg, Object... binds) {
3127
if (getLogger() != null) {
3228
getLogger().warn(msg, binds);
33-
} else if (loggingLevel >= LEVEL_WARN) {
29+
} else {
3430
ConsoleUtils.warn(msg, binds);
3531
}
3632
}
3733

3834
public void logInfo(String msg, Object... binds) {
3935
if (getLogger() != null) {
4036
getLogger().info(msg, binds);
41-
} else if (loggingLevel >= LEVEL_INFO) {
37+
} else {
4238
ConsoleUtils.info(msg, binds);
4339
}
4440
}
4541

4642
public void logDebug(String msg, Object... binds) {
4743
if (getLogger() != null) {
4844
getLogger().debug(msg, binds);
49-
} else if (loggingLevel >= LEVEL_DEBUG) {
45+
} else {
5046
ConsoleUtils.debug(msg, binds);
5147
}
5248
}
5349

5450
public void logTrace(String msg, Object... binds) {
5551
if (getLogger() != null) {
5652
getLogger().trace(msg, binds);
57-
} else if (loggingLevel >= LEVEL_TRACE) {
53+
} else {
5854
ConsoleUtils.trace(msg, binds);
5955
}
6056
}

src/main/java/com/github/exadmin/cyberferret/utils/ConsoleUtils.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,42 @@
11
package com.github.exadmin.cyberferret.utils;
22

33
public class ConsoleUtils {
4+
private static final int LEVEL_ERROR = 0;
5+
private static final int LEVEL_WARN = 1;
6+
private static final int LEVEL_INFO = 2;
7+
private static final int LEVEL_DEBUG = 3;
8+
private static final int LEVEL_TRACE = 4;
9+
10+
private static final int CUR_LOG_LEVEL = LEVEL_INFO;
411

512
private static void print(String prefix, String msg, Object... binds) {
613
String result = prefix + format(msg, binds);
714
System.out.println(result);
815
}
916

1017
public static void warn(String msg, Object ... binds) {
11-
print("[WARN ]", msg, binds);
18+
if (CUR_LOG_LEVEL == LEVEL_WARN)
19+
print("[WARN ]", msg, binds);
1220
}
1321

1422
public static void trace(String msg, Object ... binds) {
15-
print("[TRACE]", msg, binds);
23+
if (CUR_LOG_LEVEL >= LEVEL_TRACE)
24+
print("[TRACE]", msg, binds);
1625
}
1726

1827
public static void info(String msg, Object ... binds) {
19-
print("[INFO ]", msg, binds);
28+
if (CUR_LOG_LEVEL >= LEVEL_INFO)
29+
print("[INFO ]", msg, binds);
2030
}
2131

2232
public static void debug(String msg, Object ... binds) {
23-
print("[DEBUG]", msg, binds);
33+
if (CUR_LOG_LEVEL >= LEVEL_DEBUG)
34+
print("[DEBUG]", msg, binds);
2435
}
2536

2637
public static void error(String msg, Object ... binds) {
27-
print("[ERROR]", msg, binds);
38+
if (CUR_LOG_LEVEL >= LEVEL_ERROR)
39+
print("[ERROR]", msg, binds);
2840
}
2941

3042
public static String format(String msg, Object... binds) {

0 commit comments

Comments
 (0)