Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[grid] Add log-level config option #8968

Merged
merged 2 commits into from
Dec 15, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
[grid] Remove extra checks for configuring log-levels. Undo event-log…
… level change.
  • Loading branch information
pujagani committed Dec 15, 2020
commit af147021f0f70e249a4066522cb02cdd8613c9a9
20 changes: 8 additions & 12 deletions java/server/src/org/openqa/selenium/grid/log/LoggingOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public class LoggingOptions {

public static final Json JSON = new Json();

private Level level = Level.INFO;

private final Config config;

public LoggingOptions(Config config) {
Expand All @@ -93,9 +95,8 @@ public String getLogEncoding() {
return config.get(LOGGING_SECTION, "log-encoding").orElse(null);
}

public Level getLoggingLevel() {
public void setLoggingLevel() {
String configLevel = config.get(LOGGING_SECTION, "log-level").orElse(Level.INFO.getName());
Level level;

if (Level.ALL.getName().equalsIgnoreCase(configLevel)) {
level = Level.ALL;
Expand All @@ -107,19 +108,13 @@ public Level getLoggingLevel() {
level = Level.FINER;
} else if (Level.FINEST.getName().equalsIgnoreCase(configLevel)) {
level = Level.FINEST;
} else if (Level.INFO.getName().equalsIgnoreCase(configLevel)) {
level = Level.INFO;
} else if (Level.OFF.getName().equalsIgnoreCase(configLevel)) {
level = Level.OFF;
} else if (Level.SEVERE.getName().equalsIgnoreCase(configLevel)) {
level = Level.SEVERE;
} else if (Level.WARNING.getName().equalsIgnoreCase(configLevel)) {
level = Level.WARNING;
} else {
// Default logging level in case of incorrect input.
level = Level.INFO;
}
return level;
}

public Tracer getTracer() {
Expand Down Expand Up @@ -180,7 +175,7 @@ public <T> void accept(AttributeKey<T> key, T value) {
map.put("attributes", attributeMap);
String jsonString = getJsonString(map);
if (status.isOk()) {
LOG.log(Level.FINE, jsonString);
LOG.log(Level.INFO, jsonString);
} else {
LOG.log(Level.WARNING, jsonString);
}
Expand Down Expand Up @@ -238,21 +233,22 @@ public void configureLogging() {

// Now configure the root logger, since everything should flow up to that
Logger logger = logManager.getLogger("");
logger.setLevel(getLoggingLevel());
setLoggingLevel();
logger.setLevel(level);
OutputStream out = getOutputStream();
String encoding = getLogEncoding();

if (isUsingPlainLogs()) {
Handler handler = new FlushingHandler(out);
handler.setFormatter(new TerseFormatter());
handler.setLevel(getLoggingLevel());
handler.setLevel(level);
configureLogEncoding(logger, encoding, handler);
}

if (isUsingStructuredLogging()) {
Handler handler = new FlushingHandler(out);
handler.setFormatter(new JsonFormatter());
handler.setLevel(getLoggingLevel());
handler.setLevel(level);
configureLogEncoding(logger, encoding, handler);
}
}
Expand Down