Skip to content

[py][java][js] SE_DEBUG warns only when overriding user settings#17009

Merged
titusfortner merged 2 commits intotrunkfrom
warn_debug
Jan 26, 2026
Merged

[py][java][js] SE_DEBUG warns only when overriding user settings#17009
titusfortner merged 2 commits intotrunkfrom
warn_debug

Conversation

@titusfortner
Copy link
Member

🔗 Related Issues

Related to #16901 and #16903

💥 What does this PR do?

Updates SE_DEBUG warning messages across Python, Java, JavaScript when there are actual conflicts with user-specified settings.

🔧 Implementation Notes

Java:

  • ChromeDriverService, EdgeDriverService: Check for logLevel, silent, or their system properties
  • GeckoDriverService: Check for logLevel or its system property
  • DriverService: Only warn when defaulting to stderr and no system property is configured
  • LoggingOptions: Added warnings for Grid log level and output changes

Python:

  • chromium/service.py, firefox/service.py, ie/service.py: Check for both service_args conflicts AND log_output being set before warning

JavaScript:

  • logging.js: Warning already uses "may override" language which is appropriate for module-load-time behavior

🔄 Types of changes

  • Bug fix (backwards compatible)

@qodo-code-review
Copy link
Contributor

User description

🔗 Related Issues

Related to #16901 and #16903

💥 What does this PR do?

Updates SE_DEBUG warning messages across Python, Java, JavaScript when there are actual conflicts with user-specified settings.

🔧 Implementation Notes

Java:

  • ChromeDriverService, EdgeDriverService: Check for logLevel, silent, or their system properties
  • GeckoDriverService: Check for logLevel or its system property
  • DriverService: Only warn when defaulting to stderr and no system property is configured
  • LoggingOptions: Added warnings for Grid log level and output changes

Python:

  • chromium/service.py, firefox/service.py, ie/service.py: Check for both service_args conflicts AND log_output being set before warning

JavaScript:

  • logging.js: Warning already uses "may override" language which is appropriate for module-load-time behavior

🔄 Types of changes

  • Bug fix (backwards compatible)

PR Type

Bug fix


Description

  • Add conditional SE_DEBUG warnings only when overriding user settings

  • Java: Check for logLevel, silent, log-file conflicts before warning

  • Python: Detect service_args and log_output conflicts before warning

  • JavaScript: Emit SE_DEBUG warning at module load time

  • Add global warning in Debug class to avoid duplicate messages


Diagram Walkthrough

flowchart LR
  A["SE_DEBUG environment variable set"] --> B["Check for user-specified settings"]
  B --> C["logLevel/silent/log-level/log-file configured"]
  C --> D["Emit warning message"]
  B --> E["No user settings configured"]
  E --> F["Skip warning, apply defaults silently"]
Loading

File Walkthrough

Relevant files
Bug fix
11 files
ChromeDriverService.java
Add SE_DEBUG warning for Chrome log settings conflicts     
+9/-0     
EdgeDriverService.java
Add SE_DEBUG warning for Edge log settings conflicts         
+9/-0     
GeckoDriverService.java
Add SE_DEBUG warning for Firefox log level conflicts         
+5/-0     
LoggingOptions.java
Add SE_DEBUG warnings for Grid logging configuration         
+8/-0     
Debug.java
Add global SE_DEBUG warning with deduplication logic         
+10/-1   
DriverService.java
Add SE_DEBUG warning for default log output behavior         
+5/-0     
logging.js
Add SE_DEBUG warning at module initialization                       
+7/-0     
__init__.py
Add SE_DEBUG warning during module import                               
+4/-0     
service.py
Add conditional SE_DEBUG warning for Chromium conflicts   
+12/-3   
service.py
Add conditional SE_DEBUG warning for Firefox conflicts     
+14/-5   
service.py
Add conditional SE_DEBUG warning for IE conflicts               
+12/-3   

@qodo-code-review
Copy link
Contributor

qodo-code-review bot commented Jan 26, 2026

PR Compliance Guide 🔍

Below is a summary of compliance checks for this PR:

Security Compliance
🟢
No security concerns identified No security vulnerabilities detected by AI analysis. Human verification advised for critical code.
Ticket Compliance
🎫 No ticket provided
  • Create ticket/issue
Codebase Duplication Compliance
Codebase context is not defined

Follow the guide to enable codebase context checks.

Custom Compliance
🟢
Generic: Comprehensive Audit Trails

Objective: To create a detailed and reliable record of critical system actions for security analysis
and compliance.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Meaningful Naming and Self-Documenting Code

Objective: Ensure all identifiers clearly express their purpose and intent, making code
self-documenting

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Robust Error Handling and Edge Case Management

Objective: Ensure comprehensive error handling that provides meaningful context and graceful
degradation

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Error Handling

Objective: To prevent the leakage of sensitive system information through error messages while
providing sufficient detail for internal debugging.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Security-First Input Validation and Data Handling

Objective: Ensure all data inputs are validated, sanitized, and handled securely to prevent
vulnerabilities

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Logging Practices

Objective: To ensure logs are useful for debugging and auditing without exposing sensitive
information like PII, PHI, or cardholder data.

Status:
Unstructured warning logs: Newly added warning logs are emitted as plain text to System.err / logger warnings rather
than structured logs, which may not meet the checklist’s structured logging requirement
depending on project logging standards.

Referred Code
if (everything && DEBUG_WARNING_LOGGED.compareAndSet(false, true)) {
  String warn =
      "WARNING: Environment Variable `SE_DEBUG` is set; Selenium is forcing verbose logging"
          + " which may override user-specified settings.";
  System.err.println(warn);
}

Learn more about managing compliance generic rules or creating your own custom rules

  • Update
Compliance status legend 🟢 - Fully Compliant
🟡 - Partial Compliant
🔴 - Not Compliant
⚪ - Requires Further Human Verification
🏷️ - Compliance label

@selenium-ci selenium-ci added B-grid Everything grid and server related C-py Python Bindings C-java Java Bindings C-nodejs JavaScript Bindings labels Jan 26, 2026
@qodo-code-review
Copy link
Contributor

qodo-code-review bot commented Jan 26, 2026

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
General
Only warn when overriding user-configured settings

Conditionally display the SE_DEBUG warning in setLoggingLevel only when a
user-configured log level is present and being overridden.

java/src/org/openqa/selenium/grid/log/LoggingOptions.java [86-95]

 public void setLoggingLevel() {
     String configLevel = config.get(LOGGING_SECTION, "log-level").orElse(DEFAULT_LOG_LEVEL);
     if (Debug.isDebugAll()) {
-      System.err.println(
-          "WARNING: Environment Variable `SE_DEBUG` is set; forcing Grid log level to FINE and"
-              + " overriding configured log level.");
+      if (config.get(LOGGING_SECTION, "log-level").isPresent()) {
+        System.err.println(
+            "WARNING: Environment Variable `SE_DEBUG` is set; forcing Grid log level to FINE and"
+                + " overriding configured log level.");
+      }
       configLevel = Level.FINE.getName();
     }
 
     try {
-...

[To ensure code accuracy, apply this suggestion manually]

Suggestion importance[1-10]: 7

__

Why: The suggestion correctly points out that the warning about overriding a configured log level should only be displayed when a log level is actually configured, improving the accuracy of the warning message.

Medium
Prevent duplicate warnings

Add a module-level flag to ensure the SE_DEBUG warning in init.py is logged
only once per process.

py/selenium/webdriver/init.py [27-30]

-logger.warning(
-    "Environment Variable `SE_DEBUG` is set; "
-    "Selenium is forcing verbose logging which may override user-specified settings."
-)
+if not globals().get("_se_debug_warned"):
+    logger.warning(
+        "Environment Variable `SE_DEBUG` is set; "
+        "Selenium is forcing verbose logging which may override user-specified settings."
+    )
+    globals()["_se_debug_warned"] = True
  • Apply / Chat
Suggestion importance[1-10]: 7

__

Why: The suggestion correctly identifies that the warning in __init__.py can be logged multiple times and proposes a valid solution using a global flag to ensure it is only displayed once.

Medium
Use console.error for warnings

Use console.error instead of logManager.root_.warning to direct the SE_DEBUG
warning to stderr, matching behavior in other languages.

javascript/selenium-webdriver/lib/logging.js [492-494]

-logManager.root_.warning(
-  'Environment Variable `SE_DEBUG` is set; Selenium is forcing verbose logging which may override user-specified settings.',
-)
+console.error(
+  'WARNING: Environment Variable `SE_DEBUG` is set; Selenium is forcing verbose logging which may override user-specified settings.'
+);
  • Apply / Chat
Suggestion importance[1-10]: 7

__

Why: The suggestion to use console.error aligns the JavaScript implementation with other languages in the PR by directing the warning to stderr, which is more appropriate for this type of message than the configured logger output.

Medium
Switch to logger warnings

Replace System.err.println with a Logger.warning() call to align with standard
Java logging practices.

java/src/org/openqa/selenium/chrome/ChromeDriverService.java [284-286]

-System.err.println(
-    "WARNING: Environment Variable `SE_DEBUG` is set; forcing ChromeDriver --verbose and"
-        + " overriding --silent/--log-level settings.");
+Logger.getLogger(Builder.class.getName())
+    .warning("Environment Variable `SE_DEBUG` is set; forcing ChromeDriver --verbose and overriding --silent/--log-level settings.");
  • Apply / Chat
Suggestion importance[1-10]: 6

__

Why: The suggestion to use the standard logging framework instead of System.err.println promotes consistency and better practice within the codebase, allowing log handlers to process the warning.

Low
Possible issue
Use a thread-safe logger for warnings

Replace System.err.println() with a Logger instance in isDebugAll() for
thread-safe and consistent warning logging.

java/src/org/openqa/selenium/internal/Debug.java [51-60]

 public static boolean isDebugAll() {
     boolean everything = Boolean.parseBoolean(System.getenv("SE_DEBUG"));
     if (everything && DEBUG_WARNING_LOGGED.compareAndSet(false, true)) {
       String warn =
           "WARNING: Environment Variable `SE_DEBUG` is set; Selenium is forcing verbose logging"
               + " which may override user-specified settings.";
-      System.err.println(warn);
+      Logger.getLogger(Debug.class.getName()).warning(warn);
     }
     return everything;
 }
  • Apply / Chat
Suggestion importance[1-10]: 6

__

Why: The suggestion to use Logger.warning() instead of System.err.println() is a good practice for consistency with the project's logging framework, even though the thread-safety concern with a single println call is minor.

Low
Learned
best practice
Centralize duplicated warning logic

Centralize SE_DEBUG “override” warnings in Debug (or a shared utility) to avoid
duplicated strings/conditions across ChromeDriverService, EdgeDriverService,
GeckoDriverService, LoggingOptions, and DriverService, and to control “warn
once” behavior consistently.

java/src/org/openqa/selenium/chrome/ChromeDriverService.java [279-287]

 if (Debug.isDebugAll()
     && (logLevel != null
         || silent != null
         || Boolean.getBoolean(CHROME_DRIVER_SILENT_OUTPUT_PROPERTY)
         || System.getProperty(CHROME_DRIVER_LOG_LEVEL_PROPERTY) != null)) {
-  System.err.println(
-      "WARNING: Environment Variable `SE_DEBUG` is set; forcing ChromeDriver --verbose and"
-          + " overriding --silent/--log-level settings.");
+  Debug.warnSeDebugOverrides(
+      "ChromeDriver",
+      "forcing --verbose and overriding --silent/--log-level settings");
 }
  • Apply / Chat
Suggestion importance[1-10]: 6

__

Why:
Relevant best practice - Reduce duplication by centralizing repeated warning/override behavior instead of duplicating similar SE_DEBUG warning strings and logic across multiple services.

Low
Parse environment variables explicitly

Normalize and explicitly parse SE_DEBUG (e.g., true/1/yes) so values like "0" or
whitespace don’t accidentally enable debug mode, and keep semantics consistent
with Java’s Boolean.parseBoolean.

py/selenium/webdriver/init.py [22-30]

-if os.environ.get("SE_DEBUG"):
+_se_debug = os.environ.get("SE_DEBUG")
+if _se_debug and _se_debug.strip().lower() in ("1", "true", "yes", "on"):
     logger = logging.getLogger("selenium")
     logger.setLevel(logging.DEBUG)
     if not logger.handlers:
         logger.addHandler(logging.StreamHandler())
     logger.warning(
         "Environment Variable `SE_DEBUG` is set; "
         "Selenium is forcing verbose logging which may override user-specified settings."
     )

[To ensure code accuracy, apply this suggestion manually]

Suggestion importance[1-10]: 5

__

Why:
Relevant best practice - Add explicit validation/guards at integration boundaries by parsing and normalizing environment variables instead of relying on truthy string checks.

Low
  • Update

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR tightens SE_DEBUG behavior across Python, Java, and JavaScript so that verbose driver/Grid logging and stderr redirection only emit warnings when they actually override user-configured logging settings. It also standardizes SE_DEBUG messaging across bindings while preserving existing default logging behavior when no conflicts exist.

Changes:

  • Python: update Chromium, Firefox, and IE Service classes plus selenium.webdriver import-time logic to detect SE_DEBUG, remove conflicting logging arguments, redirect driver output to stderr, and warn only when overriding user-provided log args or outputs.
  • Java: extend Debug.isDebugAll, DriverService.Builder.parseLogOutput, LoggingOptions, and the Chrome/Edge/Gecko driver service builders to print explicit SE_DEBUG warnings when forcing verbose/debug logging or stderr output over user/system properties.
  • JavaScript: augment logging.js to emit a one-time SE_DEBUG warning at module load when verbose logging is enabled and may override user-specified logging settings.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
py/selenium/webdriver/ie/service.py Adds SE_DEBUG-aware handling that removes conflicting --log-level/--log-file args, forces --log-level=DEBUG, redirects IE driver logs to stderr, and logs a warning only when a user-specified log level or output exists.
py/selenium/webdriver/firefox/service.py Updates Firefox Service to detect SE_DEBUG, clean existing --log arguments, force --log debug with stderr output, and warn when these changes override either service args or an explicit log_output.
py/selenium/webdriver/chromium/service.py Enhances Chromium Service to treat SE_DEBUG as forcing --verbose with stderr, removing existing log-level/log-path/silent args and warning when either those args or log_output would be overridden.
py/selenium/webdriver/__init__.py On import, when SE_DEBUG is set, configures the root Selenium Python logger for DEBUG and emits a warning that verbose logging may override user-specified settings.
javascript/selenium-webdriver/lib/logging.js Introduces a module-level seDebugWarningEmitted flag and logs a one-time SE_DEBUG warning when enabling verbose logging in Node environments.
java/src/org/openqa/selenium/internal/Debug.java Extends isDebugAll() to print a single process-wide SE_DEBUG warning using an AtomicBoolean guard while preserving the existing boolean check on the environment variable.
java/src/org/openqa/selenium/remote/service/DriverService.java Adjusts parseLogOutput so that when SE_DEBUG is set and no driver log property is configured, logs a warning about defaulting driver log output to stderr before applying that default.
java/src/org/openqa/selenium/grid/log/LoggingOptions.java In SE_DEBUG mode, now warns when forcing Grid log level to FINE and when defaulting Grid log output to stderr instead of stdout if no log file is configured.
java/src/org/openqa/selenium/firefox/GeckoDriverService.java In the builder’s loadSystemProperties, adds a SE_DEBUG-specific warning when an explicit log level or log-level property is present but will be overridden by forcing GeckoDriver to DEBUG.
java/src/org/openqa/selenium/edge/EdgeDriverService.java Extends loadSystemProperties to warn when SE_DEBUG forces --verbose and overrides any existing silent/log-level configuration for EdgeDriver.
java/src/org/openqa/selenium/chrome/ChromeDriverService.java Mirrors Edge behavior for ChromeDriver by warning when SE_DEBUG-driven --verbose overrides silent/log-level configuration, while keeping existing verbose/silent precedence intact.

@titusfortner titusfortner merged commit 0c2aff1 into trunk Jan 26, 2026
92 of 95 checks passed
@titusfortner titusfortner deleted the warn_debug branch January 26, 2026 21:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

B-grid Everything grid and server related C-java Java Bindings C-nodejs JavaScript Bindings C-py Python Bindings Review effort 2/5

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants