|
5 | 5 | import java.io.OutputStream;
|
6 | 6 | import java.security.PrivilegedAction;
|
7 | 7 | 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; |
9 | 12 |
|
10 | 13 | import static java.lang.ClassLoader.getSystemClassLoader;
|
11 | 14 | import static java.lang.System.getProperty;
|
12 | 15 | import static java.lang.System.getenv;
|
13 | 16 | import static java.security.AccessController.doPrivileged;
|
14 | 17 | 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.*; |
17 | 19 | import static java.util.logging.LogManager.getLogManager;
|
18 | 20 |
|
19 | 21 | public class Handler extends StreamHandler {
|
@@ -67,18 +69,30 @@ protected Formatter determineFormatter() {
|
67 | 69 |
|
68 | 70 | protected Level determineLevel() {
|
69 | 71 | return findProperty(getClass(), "level")
|
70 |
| - .map(value -> parse(value.trim())) |
| 72 | + .map(this::parseLevel) |
71 | 73 | .orElse(ALL);
|
72 | 74 | }
|
73 | 75 |
|
74 | 76 | protected void patchGlobalLevelIfRequired() {
|
75 | 77 | findSystemProperty("log.level", "LOG_LEVEL")
|
76 |
| - .map(String::trim) |
77 |
| - .map(String::toUpperCase) |
78 |
| - .map(Level::parse) |
| 78 | + .map(this::parseLevel) |
79 | 79 | .ifPresent(level -> getLogManager().getLogger("").setLevel(level));
|
80 | 80 | }
|
81 | 81 |
|
| 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 | + |
82 | 96 | protected Object newInstanceOf(String className) {
|
83 | 97 | try {
|
84 | 98 | //noinspection deprecation
|
|
0 commit comments