Skip to content

Commit dee73cc

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 dee73cc

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,21 @@
1414

1515
import com.github.weisj.jsvg.logging.LogManager;
1616
import com.github.weisj.jsvg.logging.Logger;
17+
import com.github.weisj.jsvg.logging.Logger.Level;
1718

1819
public class JVSGLoggerLogManager implements LogManager {
1920

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

2233
@Override
2334
public Logger createLogger(String name) {

0 commit comments

Comments
 (0)