Skip to content

Commit 71dde93

Browse files
authored
[grid] Silent fail on invalid log level (SeleniumHQ#15796)
* [grid] Silent fail on invalid log level Fixing issue where providing an invalid log level to Grid will fail silently. Since the logger is not yet configured a stacktrace with the exception is printed to console and we continue since the default log level is already configured. Fixes SeleniumHQ#15790 * [grid] Silent fail on invalid log level Adding link to logging levels as suggested by @diemol and formatting. * [grid] Silent fail on invalid log level Adding hardcoded log levels as suggested by review.
1 parent c3f1b5f commit 71dde93

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

java/src/org/openqa/selenium/grid/log/LoggingOptions.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.io.UnsupportedEncodingException;
2525
import java.util.Arrays;
2626
import java.util.Enumeration;
27+
import java.util.List;
2728
import java.util.Locale;
2829
import java.util.logging.Handler;
2930
import java.util.logging.Level;
@@ -49,6 +50,17 @@ public class LoggingOptions {
4950
private final Config config;
5051
private Level level = Level.INFO;
5152
public static final String DEFAULT_LOG_TIMESTAMP_FORMAT = "HH:mm:ss.SSS";
53+
private static final List<Level> DEFAULT_LOG_LEVELS =
54+
Arrays.asList(
55+
Level.ALL,
56+
Level.INFO,
57+
Level.CONFIG,
58+
Level.FINE,
59+
Level.FINER,
60+
Level.FINEST,
61+
Level.OFF,
62+
Level.SEVERE,
63+
Level.WARNING);
5264

5365
public LoggingOptions(Config config) {
5466
this.config = Require.nonNull("Config", config);
@@ -76,7 +88,15 @@ public void setLoggingLevel() {
7688
try {
7789
level = Level.parse(configLevel.toUpperCase(Locale.ROOT));
7890
} catch (IllegalArgumentException e) {
79-
throw new ConfigException("Unable to determine log level from " + configLevel);
91+
// Logger is not configured yet
92+
new ConfigException(
93+
"Unable to determine log level from "
94+
+ configLevel
95+
+ ". Using default "
96+
+ DEFAULT_LOG_LEVEL
97+
+ ". Available log levels are: "
98+
+ DEFAULT_LOG_LEVELS)
99+
.printStackTrace();
80100
}
81101
}
82102

0 commit comments

Comments
 (0)