Skip to content

Commit

Permalink
[Java] Add back log argument to the server
Browse files Browse the repository at this point in the history
  • Loading branch information
AutomatedTester committed Jun 9, 2020
1 parent 6bb623f commit dae6db2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ public class LoggingFlags implements HasRoles {
@ConfigValue(section = "logging", name = "tracing", example = "true")
private Boolean enableTracing = true;

@Parameter(description = "File to write out logs", hidden = true, names = "--log", arity = 1)
@ConfigValue(section = "logging", name = "log-file", example = "true")
private String logFile;

@Override
public Set<Role> getRoles() {
return ALL_ROLES;
Expand Down
24 changes: 21 additions & 3 deletions java/server/src/org/openqa/selenium/grid/log/LoggingOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
import org.openqa.selenium.remote.tracing.empty.NullTracer;
import org.openqa.selenium.remote.tracing.opentelemetry.OpenTelemetryTracer;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.Collection;
import java.util.Enumeration;
Expand Down Expand Up @@ -141,17 +144,32 @@ 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) {

}

if (isUsingPlainLogs()) {
Handler handler = new FlushingHandler(System.out);
Handler handler = new FlushingHandler(out);
handler.setFormatter(new TerseFormatter());
logger.addHandler(handler);
}
}

if (isUsingStructuredLogging()) {
Handler handler = new FlushingHandler(System.out);
Handler handler = new FlushingHandler(out);
handler.setFormatter(new JsonFormatter());
logger.addHandler(handler);
}
}

private OutputStream getOutputStream() throws FileNotFoundException {
String fileName = config.get(LOGGING_SECTION, "log-file").get();
FileOutputStream fileOut = null;
if (fileName != "null") {
fileOut = new FileOutputStream(fileName);
}
return fileOut;
}
}

0 comments on commit dae6db2

Please sign in to comment.