diff --git a/java/server/src/org/openqa/selenium/grid/log/LoggingOptions.java b/java/server/src/org/openqa/selenium/grid/log/LoggingOptions.java index 975a68f6a27cb..2caed6aca63b9 100644 --- a/java/server/src/org/openqa/selenium/grid/log/LoggingOptions.java +++ b/java/server/src/org/openqa/selenium/grid/log/LoggingOptions.java @@ -34,6 +34,7 @@ import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.OutputStream; +import java.io.UncheckedIOException; import java.util.Arrays; import java.util.Collection; import java.util.Enumeration; @@ -144,12 +145,7 @@ public void configureLogging() { // Now configure the root logger, since everything should flow up to that Logger logger = logManager.getLogger(""); - OutputStream out = System.out; - try { - out = getOutputStream(); - } catch (FileNotFoundException e) { - - } + OutputStream out = getOutputStream(); if (isUsingPlainLogs()) { Handler handler = new FlushingHandler(out); @@ -164,15 +160,15 @@ public void configureLogging() { } } - private OutputStream getOutputStream() throws FileNotFoundException { - String fileName = config.get(LOGGING_SECTION, "log-file").orElse("null"); - OutputStream fileOut = null; - if (fileName != "null") { - fileOut = new FileOutputStream(fileName); - } - if (fileOut == null) { - fileOut = System.out; - } - return fileOut; + private OutputStream getOutputStream() { + return config.get(LOGGING_SECTION, "log-file") + .map(fileName -> { + try { + return (OutputStream) new FileOutputStream(fileName); + } catch (FileNotFoundException e) { + throw new UncheckedIOException(e); + } + }) + .orElse(System.out); } }