Skip to content

Commit 5690d5f

Browse files
committed
* log: config output level via LogLevels.infoLevel()/traceLevel(), make it possible to reduce unnecessary external logs
Signed-off-by: neo <1100909+neowu@users.noreply.github.com>
1 parent ec661c7 commit 5690d5f

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

core-ng/src/main/java/core/framework/log/LogLevels.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,13 @@ public final class LogLevels {
2424
traceLevels.add(new Entry("org.xnio", LogLevel.INFO));
2525
}
2626

27-
public static void infoLevel(String prefix, LogLevel level) {
28-
if (infoLevels == null) throw new Error("log levels must be configured before slf4j initialization");
29-
infoLevels.add(new Entry(prefix, level));
30-
}
31-
32-
public static void traceLevel(String prefix, LogLevel level) {
33-
if (traceLevels == null) throw new Error("log levels must be configured before slf4j initialization");
34-
traceLevels.add(new Entry(prefix, level));
27+
// action log trace collects logs where level >= traceLevel, logs where level >= infoLevel will be printed out to console always
28+
public static void add(String prefix, LogLevel traceLevel, LogLevel infoLevel) {
29+
if (traceLevels == null || infoLevels == null) throw new Error("log levels must be configured before slf4j initialization");
30+
if (traceLevel.value > infoLevel.value)
31+
throw new Error("log with info level less than trace level may not be printed, prefix=" + prefix); // refer to core.framework.internal.log.LoggerImpl.log()
32+
traceLevels.add(new Entry(prefix, traceLevel));
33+
infoLevels.add(new Entry(prefix, infoLevel));
3534
}
3635

3736
public static DefaultLoggerFactory createLoggerFactory() {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package core.framework.log;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
6+
7+
class LogLevelsTest {
8+
@Test
9+
void add() {
10+
assertThatThrownBy(() -> {
11+
LogLevels.add("com.test.", LogLevel.WARN, LogLevel.INFO);
12+
}).hasMessageContaining("log with info level less than trace level may not be printed");
13+
}
14+
}

0 commit comments

Comments
 (0)