Skip to content

Commit 0c2aff1

Browse files
authored
[py][java][js] SE_DEBUG warns only when overriding user settings (#17009)
* [py][java][js][rb] SE_DEBUG warns only when overriding user settings
1 parent caffe95 commit 0c2aff1

11 files changed

Lines changed: 93 additions & 12 deletions

File tree

java/src/org/openqa/selenium/chrome/ChromeDriverService.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,15 @@ protected void loadSystemProperties() {
276276
}
277277
if (Debug.isDebugAll()
278278
|| (verbose == null && Boolean.getBoolean(CHROME_DRIVER_VERBOSE_LOG_PROPERTY))) {
279+
if (Debug.isDebugAll()
280+
&& (logLevel != null
281+
|| silent != null
282+
|| Boolean.getBoolean(CHROME_DRIVER_SILENT_OUTPUT_PROPERTY)
283+
|| System.getProperty(CHROME_DRIVER_LOG_LEVEL_PROPERTY) != null)) {
284+
System.err.println(
285+
"WARNING: Environment Variable `SE_DEBUG` is set; forcing ChromeDriver --verbose and"
286+
+ " overriding --silent/--log-level settings.");
287+
}
279288
withVerbose(true);
280289
}
281290
if (silent == null && Boolean.getBoolean(CHROME_DRIVER_SILENT_OUTPUT_PROPERTY)) {

java/src/org/openqa/selenium/edge/EdgeDriverService.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,15 @@ protected void loadSystemProperties() {
270270
}
271271
if (Debug.isDebugAll()
272272
|| (verbose == null && Boolean.getBoolean(EDGE_DRIVER_VERBOSE_LOG_PROPERTY))) {
273+
if (Debug.isDebugAll()
274+
&& (logLevel != null
275+
|| silent != null
276+
|| Boolean.getBoolean(EDGE_DRIVER_SILENT_OUTPUT_PROPERTY)
277+
|| System.getProperty(EDGE_DRIVER_LOG_LEVEL_PROPERTY) != null)) {
278+
System.err.println(
279+
"WARNING: Environment Variable `SE_DEBUG` is set; forcing EdgeDriver --verbose and"
280+
+ " overriding --silent/--log-level settings.");
281+
}
273282
withVerbose(true);
274283
}
275284
if (silent == null && Boolean.getBoolean(EDGE_DRIVER_SILENT_OUTPUT_PROPERTY)) {

java/src/org/openqa/selenium/firefox/GeckoDriverService.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,11 @@ public GeckoDriverService.Builder withWebSocketPort(@Nullable Integer websocketP
235235
protected void loadSystemProperties() {
236236
parseLogOutput(GECKO_DRIVER_LOG_PROPERTY);
237237
if (Debug.isDebugAll()) {
238+
if (logLevel != null || System.getProperty(GECKO_DRIVER_LOG_LEVEL_PROPERTY) != null) {
239+
System.err.println(
240+
"WARNING: Environment Variable `SE_DEBUG` is set; forcing GeckoDriver log level to"
241+
+ " DEBUG and overriding configured log level.");
242+
}
238243
logLevel = FirefoxDriverLogLevel.DEBUG;
239244
} else if (logLevel == null) {
240245
logLevel =

java/src/org/openqa/selenium/grid/log/LoggingOptions.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ public String getLogEncoding() {
8686
public void setLoggingLevel() {
8787
String configLevel = config.get(LOGGING_SECTION, "log-level").orElse(DEFAULT_LOG_LEVEL);
8888
if (Debug.isDebugAll()) {
89+
System.err.println(
90+
"WARNING: Environment Variable `SE_DEBUG` is set; forcing Grid log level to FINE and"
91+
+ " overriding configured log level.");
8992
configLevel = Level.FINE.getName();
9093
}
9194

@@ -183,6 +186,11 @@ private void configureLogEncoding(Logger logger, String encoding, Handler handle
183186
}
184187

185188
private OutputStream getOutputStream() {
189+
if (Debug.isDebugAll() && config.get(LOGGING_SECTION, "log-file").isEmpty()) {
190+
System.err.println(
191+
"WARNING: Environment Variable `SE_DEBUG` is set; defaulting Grid log output to stderr"
192+
+ " instead of stdout.");
193+
}
186194
return config
187195
.get(LOGGING_SECTION, "log-file")
188196
.map(

java/src/org/openqa/selenium/internal/Debug.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package org.openqa.selenium.internal;
1919

20+
import java.util.concurrent.atomic.AtomicBoolean;
2021
import java.util.logging.Level;
2122
import java.util.logging.Logger;
2223
import java.util.logging.SimpleFormatter;
@@ -26,6 +27,7 @@
2627
public class Debug {
2728

2829
private static final boolean IS_DEBUG;
30+
private static final AtomicBoolean DEBUG_WARNING_LOGGED = new AtomicBoolean(false);
2931
private static boolean loggerConfigured = false;
3032
private static Logger seleniumLogger;
3133

@@ -47,7 +49,14 @@ public static Level getDebugLogLevel() {
4749
}
4850

4951
public static boolean isDebugAll() {
50-
return Boolean.parseBoolean(System.getenv("SE_DEBUG"));
52+
boolean everything = Boolean.parseBoolean(System.getenv("SE_DEBUG"));
53+
if (everything && DEBUG_WARNING_LOGGED.compareAndSet(false, true)) {
54+
String warn =
55+
"WARNING: Environment Variable `SE_DEBUG` is set; Selenium is forcing verbose logging"
56+
+ " which may override user-specified settings.";
57+
System.err.println(warn);
58+
}
59+
return everything;
5160
}
5261

5362
public static void configureLogger() {

java/src/org/openqa/selenium/remote/service/DriverService.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,11 @@ protected void parseLogOutput(String logProperty) {
485485

486486
String defaultLocation = Debug.isDebugAll() ? LOG_STDERR : LOG_NULL;
487487
String logLocation = System.getProperty(logProperty, defaultLocation);
488+
if (Debug.isDebugAll() && System.getProperty(logProperty) == null) {
489+
System.err.println(
490+
"WARNING: Environment Variable `SE_DEBUG` is set; defaulting driver log output to"
491+
+ " stderr.");
492+
}
488493
switch (logLocation) {
489494
case LOG_STDOUT:
490495
withLogOutput(System.out);

javascript/selenium-webdriver/lib/logging.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,11 @@ const logManager = new LogManager()
486486
if (typeof process !== 'undefined' && process.env && (process.env.SE_DEBUG || process.env.SELENIUM_VERBOSE)) {
487487
logManager.root_.setLevel(Level.ALL)
488488
logManager.root_.addHandler(consoleHandler)
489+
if (process.env.SE_DEBUG) {
490+
logManager.root_.warning(
491+
'Environment Variable `SE_DEBUG` is set; Selenium is forcing verbose logging which may override user-specified settings.',
492+
)
493+
}
489494
}
490495

491496
/**

py/selenium/webdriver/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
logger.setLevel(logging.DEBUG)
2626
if not logger.handlers:
2727
logger.addHandler(logging.StreamHandler())
28+
logger.warning(
29+
"Environment Variable `SE_DEBUG` is set; "
30+
"Selenium is forcing verbose logging which may override user-specified settings."
31+
)
2832

2933
__version__ = "4.41.0.202601181916"
3034

py/selenium/webdriver/chromium/service.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18+
import logging
1819
import os
1920
import sys
2021
from collections.abc import Mapping, Sequence
@@ -55,9 +56,17 @@ def __init__(
5556
self.log_output = log_output
5657

5758
if os.environ.get("SE_DEBUG"):
58-
self._service_args = [
59-
arg for arg in self._service_args if not any(x in arg for x in ("log-level", "log-path", "silent"))
60-
]
59+
has_arg_conflicts = any(x in arg for arg in self._service_args for x in ("log-level", "log-path", "silent"))
60+
has_output_conflict = self.log_output is not None
61+
if has_arg_conflicts or has_output_conflict:
62+
logging.getLogger(__name__).warning(
63+
"Environment Variable `SE_DEBUG` is set; "
64+
"forcing ChromiumDriver --verbose and overriding log-level/log-output/silent settings."
65+
)
66+
if has_arg_conflicts:
67+
self._service_args = [
68+
arg for arg in self._service_args if not any(x in arg for x in ("log-level", "log-path", "silent"))
69+
]
6170
self._service_args.append("--verbose")
6271
self.log_output = sys.stderr
6372

py/selenium/webdriver/firefox/service.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18+
import logging
1819
import os
1920
import sys
2021
from collections.abc import Mapping, Sequence
@@ -49,11 +50,19 @@ def __init__(
4950
driver_path_env_key = driver_path_env_key or "SE_GECKODRIVER"
5051

5152
if os.environ.get("SE_DEBUG"):
52-
if "--log" in self._service_args:
53-
idx = self._service_args.index("--log")
54-
del self._service_args[idx : idx + 2]
55-
else:
56-
self._service_args = [arg for arg in self._service_args if not arg.startswith("--log=")]
53+
has_log_arg = "--log" in self._service_args or any(arg.startswith("--log=") for arg in self._service_args)
54+
has_output_conflict = log_output is not None
55+
if has_log_arg or has_output_conflict:
56+
logging.getLogger(__name__).warning(
57+
"Environment Variable `SE_DEBUG` is set; "
58+
"forcing GeckoDriver log level to DEBUG and overriding configured log level/output."
59+
)
60+
if has_log_arg:
61+
if "--log" in self._service_args:
62+
idx = self._service_args.index("--log")
63+
del self._service_args[idx : idx + 2]
64+
else:
65+
self._service_args = [arg for arg in self._service_args if not arg.startswith("--log=")]
5766
self._service_args.append("--log")
5867
self._service_args.append("debug")
5968
log_output = sys.stderr

0 commit comments

Comments
 (0)