Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 4 additions & 2 deletions java/src/org/openqa/selenium/chrome/ChromeDriverService.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.chromium.ChromiumDriverLogLevel;
import org.openqa.selenium.internal.Debug;
import org.openqa.selenium.remote.service.DriverFinder;
import org.openqa.selenium.remote.service.DriverService;

Expand Down Expand Up @@ -273,8 +274,9 @@ protected void loadSystemProperties() {
if (appendLog == null) {
this.appendLog = Boolean.getBoolean(CHROME_DRIVER_APPEND_LOG_PROPERTY);
}
if (verbose == null && Boolean.getBoolean(CHROME_DRIVER_VERBOSE_LOG_PROPERTY)) {
withVerbose(Boolean.getBoolean(CHROME_DRIVER_VERBOSE_LOG_PROPERTY));
if (Debug.isDebugAll()
|| (verbose == null && Boolean.getBoolean(CHROME_DRIVER_VERBOSE_LOG_PROPERTY))) {
withVerbose(true);
}
if (silent == null && Boolean.getBoolean(CHROME_DRIVER_SILENT_OUTPUT_PROPERTY)) {
withSilent(Boolean.getBoolean(CHROME_DRIVER_SILENT_OUTPUT_PROPERTY));
Expand Down
6 changes: 4 additions & 2 deletions java/src/org/openqa/selenium/edge/EdgeDriverService.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.chromium.ChromiumDriverLogLevel;
import org.openqa.selenium.internal.Debug;
import org.openqa.selenium.remote.service.DriverFinder;
import org.openqa.selenium.remote.service.DriverService;

Expand Down Expand Up @@ -267,8 +268,9 @@ protected void loadSystemProperties() {
if (appendLog == null) {
this.appendLog = Boolean.getBoolean(EDGE_DRIVER_APPEND_LOG_PROPERTY);
}
if (verbose == null && Boolean.getBoolean(EDGE_DRIVER_VERBOSE_LOG_PROPERTY)) {
withVerbose(Boolean.getBoolean(EDGE_DRIVER_VERBOSE_LOG_PROPERTY));
if (Debug.isDebugAll()
|| (verbose == null && Boolean.getBoolean(EDGE_DRIVER_VERBOSE_LOG_PROPERTY))) {
withVerbose(true);
}
if (silent == null && Boolean.getBoolean(EDGE_DRIVER_SILENT_OUTPUT_PROPERTY)) {
withSilent(Boolean.getBoolean(EDGE_DRIVER_SILENT_OUTPUT_PROPERTY));
Expand Down
11 changes: 6 additions & 5 deletions java/src/org/openqa/selenium/firefox/GeckoDriverService.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.jspecify.annotations.Nullable;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.internal.Debug;
import org.openqa.selenium.net.PortProber;
import org.openqa.selenium.remote.service.DriverService;

Expand Down Expand Up @@ -233,11 +234,11 @@ public GeckoDriverService.Builder withWebSocketPort(@Nullable Integer websocketP
@Override
protected void loadSystemProperties() {
parseLogOutput(GECKO_DRIVER_LOG_PROPERTY);
if (logLevel == null) {
String logFilePath = System.getProperty(GECKO_DRIVER_LOG_LEVEL_PROPERTY);
if (logFilePath != null) {
this.logLevel = FirefoxDriverLogLevel.fromString(logFilePath);
}
if (Debug.isDebugAll()) {
logLevel = FirefoxDriverLogLevel.DEBUG;
} else if (logLevel == null) {
logLevel =
FirefoxDriverLogLevel.fromString(System.getProperty(GECKO_DRIVER_LOG_LEVEL_PROPERTY));
}
if (logTruncate == null) {
logTruncate = !Boolean.getBoolean(GECKO_DRIVER_LOG_NO_TRUNCATE);
Expand Down
6 changes: 5 additions & 1 deletion java/src/org/openqa/selenium/grid/log/LoggingOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.logging.Logger;
import org.openqa.selenium.grid.config.Config;
import org.openqa.selenium.grid.config.ConfigException;
import org.openqa.selenium.internal.Debug;
import org.openqa.selenium.internal.Require;
import org.openqa.selenium.remote.tracing.Tracer;
import org.openqa.selenium.remote.tracing.empty.NullTracer;
Expand Down Expand Up @@ -84,6 +85,9 @@ public String getLogEncoding() {

public void setLoggingLevel() {
String configLevel = config.get(LOGGING_SECTION, "log-level").orElse(DEFAULT_LOG_LEVEL);
if (Debug.isDebugAll()) {
configLevel = Level.FINE.getName();
}

try {
level = Level.parse(configLevel.toUpperCase(Locale.ROOT));
Expand Down Expand Up @@ -189,7 +193,7 @@ private OutputStream getOutputStream() {
throw new UncheckedIOException(e);
}
})
.orElse(System.out);
.orElseGet(() -> Debug.isDebugAll() ? System.err : System.out);
}

public String getLogTimestampFormat() {
Expand Down
30 changes: 25 additions & 5 deletions java/src/org/openqa/selenium/internal/Debug.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,20 @@
package org.openqa.selenium.internal;

import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;
import java.util.logging.StreamHandler;

/** Used to provide information about whether Selenium is running under debug mode. */
public class Debug {

private static final boolean IS_DEBUG;
private static boolean loggerConfigured = false;
private static Logger seleniumLogger;

static {
boolean simpleProperty = Boolean.getBoolean("selenium.debug");
boolean longerProperty = Boolean.getBoolean("selenium.webdriver.verbose");
boolean envVar = Boolean.parseBoolean(System.getenv("SE_DEBUG"));

IS_DEBUG = simpleProperty || longerProperty || envVar;
IS_DEBUG =
Boolean.getBoolean("selenium.debug") || Boolean.getBoolean("selenium.webdriver.verbose");
}

private Debug() {
Expand All @@ -43,4 +45,22 @@ public static boolean isDebugging() {
public static Level getDebugLogLevel() {
return isDebugging() ? Level.INFO : Level.FINE;
}

public static boolean isDebugAll() {
return Boolean.parseBoolean(System.getenv("SE_DEBUG"));
}

public static void configureLogger() {
if (!isDebugAll() || loggerConfigured) {
return;
}

seleniumLogger = Logger.getLogger("org.openqa.selenium");
seleniumLogger.setLevel(Level.FINE);

StreamHandler handler = new StreamHandler(System.err, new SimpleFormatter());
handler.setLevel(Level.FINE);
seleniumLogger.addHandler(handler);
loggerConfigured = true;
}
}
4 changes: 4 additions & 0 deletions java/src/org/openqa/selenium/remote/RemoteWebDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ public class RemoteWebDriver
PrintsPage,
TakesScreenshot {

static {
org.openqa.selenium.internal.Debug.configureLogger();
}

private static final Logger LOG = Logger.getLogger(RemoteWebDriver.class.getName());

/** Boolean system property that defines whether the tracing is enabled or not. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.ImmutableCapabilities;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.internal.Debug;
import org.openqa.selenium.internal.Require;
import org.openqa.selenium.net.PortProber;
import org.openqa.selenium.net.UrlChecker;
Expand Down Expand Up @@ -482,7 +483,8 @@ protected void parseLogOutput(String logProperty) {
return;
}

String logLocation = System.getProperty(logProperty, LOG_NULL);
String defaultLocation = Debug.isDebugAll() ? LOG_STDERR : LOG_NULL;
String logLocation = System.getProperty(logProperty, defaultLocation);
switch (logLocation) {
case LOG_STDOUT:
withLogOutput(System.out);
Expand Down