Skip to content

Commit

Permalink
[java] Refactoring initialization of output stream in LoggingOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
barancev committed Jun 16, 2020
1 parent 2f20aff commit d7a3443
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions java/server/src/org/openqa/selenium/grid/log/LoggingOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
}

0 comments on commit d7a3443

Please sign in to comment.