Skip to content

Commit d63140f

Browse files
committed
Add robust log level handling in JVSGLoggerLogManager
The JVSGLoggerLogManager allows to customize the log level with a system property. When an invalid log level is passed, the call currently throws an exception and makes the whole rasterizer initialization fail, leading to the non-availability of an SVG rasterizer throughout the whole application lifecycle. This change makes the system property processing more robust: when an invalid level is used, an error is printed and the implementation falls back to using "ERROR" as default log level. In addition, capitalization is ignored by always making the passed value upper case. As a result of this change, it not be possible to make the rasterizer implementation fail with an invalid system property anymore.
1 parent c1fd7a0 commit d63140f

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

bundles/org.eclipse.swt.svg/src/org/eclipse/swt/svg/logging/JVSGLoggerLogManager.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,17 @@
1717

1818
public class JVSGLoggerLogManager implements LogManager {
1919

20-
private static final Logger.Level LEVEL = Logger.Level.valueOf(System.getProperty("org.eclipse.swt.svg.logging", "ERROR"));
20+
private static final Logger.Level LEVEL = getLogLevel();
21+
22+
private static Logger.Level getLogLevel() {
23+
try {
24+
return Enum.valueOf(Logger.Level.class, System.getProperty("org.eclipse.swt.svg.logging", "ERROR").toUpperCase());
25+
} catch (IllegalArgumentException e) {
26+
System.err.format("JSVGRasterizer: Invalid log level specified: %s. Defaulting to ERROR.",
27+
System.getProperty("org.eclipse.swt.svg.logging")).println();
28+
return Logger.Level.ERROR;
29+
}
30+
}
2131

2232
@Override
2333
public Logger createLogger(String name) {

0 commit comments

Comments
 (0)