Skip to content

Commit a7c951b

Browse files
committed
* Improve parsing of levels... also accept DEBUG etc
1 parent 2a734c8 commit a7c951b

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

core/src/main/java/org/echocat/tjl/Handler.java

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@
55
import java.io.OutputStream;
66
import java.security.PrivilegedAction;
77
import java.util.Optional;
8-
import java.util.logging.*;
8+
import java.util.logging.Formatter;
9+
import java.util.logging.Level;
10+
import java.util.logging.LogRecord;
11+
import java.util.logging.StreamHandler;
912

1013
import static java.lang.ClassLoader.getSystemClassLoader;
1114
import static java.lang.System.getProperty;
1215
import static java.lang.System.getenv;
1316
import static java.security.AccessController.doPrivileged;
1417
import static java.util.Optional.ofNullable;
15-
import static java.util.logging.Level.ALL;
16-
import static java.util.logging.Level.parse;
18+
import static java.util.logging.Level.*;
1719
import static java.util.logging.LogManager.getLogManager;
1820

1921
public class Handler extends StreamHandler {
@@ -67,18 +69,30 @@ protected Formatter determineFormatter() {
6769

6870
protected Level determineLevel() {
6971
return findProperty(getClass(), "level")
70-
.map(value -> parse(value.trim()))
72+
.map(this::parseLevel)
7173
.orElse(ALL);
7274
}
7375

7476
protected void patchGlobalLevelIfRequired() {
7577
findSystemProperty("log.level", "LOG_LEVEL")
76-
.map(String::trim)
77-
.map(String::toUpperCase)
78-
.map(Level::parse)
78+
.map(this::parseLevel)
7979
.ifPresent(level -> getLogManager().getLogger("").setLevel(level));
8080
}
8181

82+
protected Level parseLevel(String plain) {
83+
final String input = plain.trim().toUpperCase();
84+
if (input.equals("DEBUG")) {
85+
return FINE;
86+
}
87+
if (input.equals("TRACE")) {
88+
return FINEST;
89+
}
90+
if (input.equals("ERROR") || input.equals("FATAL")) {
91+
return SEVERE;
92+
}
93+
return Level.parse(input);
94+
}
95+
8296
protected Object newInstanceOf(String className) {
8397
try {
8498
//noinspection deprecation

0 commit comments

Comments
 (0)