[java] SE_DEBUG dumps all log output to stderr#16900
Conversation
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
||||||||||||||||||||||||||||||||
PR Code Suggestions ✨Explore these optional code suggestions:
|
||||||||||||||||||||
asolntsev
left a comment
There was a problem hiding this comment.
I have to repeat myself:
This specific PR can be merged since it doesn't make things worth.
But generally, it's a wrong approach to enable debug logs in Java.
The right approach is the following:
-
Java code always logs "debug" message:
LOG.debug("Here comes some debugging info rarely useful"); -
Users have configuration file, say, logback.xml - where they can enable or disable debug logs for some specific packages or classes:
<configuration>
<!-- Console / file / kafka / ... appender -->
<appender name="CONSOLE" class="..."/>
<!-- Enable DEBUG only for this package -->
<logger name="org.openqa.selenium" level="DEBUG"/>
<!-- Root logger (everything else is logged with INFO by default) -->
<root level="INFO">
<appender-ref ref="CONSOLE"/>
</root>
</configuration>|
It's a feature that Selenium doesn't require slf4j, and doesn't force any particular logging dependencies on users. if they know what they are doing with logging, it's easy enough for them to add the required configs. The problem is how to help them when they don't know what they are doing. I guess we could implement our internal testing framework code with slf4j to accomplish what I'm suggesting. But I think there is value in having this come from the library directly. All that being said, I'm not sure we want this toggle to be what we advertise to users. I'm interested in a way for me to see the issues like what is timing out where. The only restriction I have is that if a user toggles it, I don't want it to get in the way of whatever other logging solution(s) they may have. |
|
I understand. In JUL, we need to have a file named # Global default
.level = INFO
# Enable DEBUG-like logging for a specific package
org.openqa.selenium.bidi.level = FINE
# Make sure handlers actually output FINE
java.util.logging.ConsoleHandler.level = FINE
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter |
|
I guess I'm still trying to understand if you are suggesting a different approach to the functionality I'd like to see. You'd rather we put something in our test framework rather than hard coding it in the library directly? |
Yes, I am suggesting a different approach.
But we can do it later, it doesn't stop us from merging this PR. |
Oh, that, yes, 💯 agree. I'm planning to submit a deprecation for that one and point people to docs (we probably also need to improve those). But that's why this PR completely changed away from what the system properties are doing. |
User description
🔗 Related Issues
Existing
Debug.javaimplementation uses a clever trick to provide additional debugging info via system property by logging things that are normally "FINE" level at "INFO" so they are seen by the user without messing with their other logging setup. (See #12892)So when I implemented #16816 I did the easy thing ad used it to toggle the clever behavior. Except this usage isn't consistent in the codebase, so it doesn't actually do that much.
💥 What does this PR do?
SE_DEBUGis set.FINE/DEBUGsent to stderr🔧 Implementation Notes
SE_DEBUGset for Selenium manager this will add a lot of extra output, so could beSE_DEBUG_ALL?💡 Additional Considerations
Other languages next
🔄 Types of changes
PR Type
Enhancement
Description
Adds
SE_DEBUGenvironment variable support for comprehensive debug loggingRoutes all Selenium debug output to stderr when
SE_DEBUGis enabledOverrides driver and grid logging to use
FINE/DEBUGlevel with stderr outputConfigures JUL handler for Selenium package to capture all debug information
Diagram Walkthrough
File Walkthrough
Debug.java
Add SE_DEBUG support and logger configurationjava/src/org/openqa/selenium/internal/Debug.java
SE_DEBUGenvironment variable check into newisDebugAll()method
SE_DEBUGfrom staticIS_DEBUGinitializationconfigureLogger()method to set up JUL handler for stderr outputStreamHandlerwithDebugLogFormatterfor Selenium packagelogging
ChromeDriverService.java
Enable verbose logging when SE_DEBUG is setjava/src/org/openqa/selenium/chrome/ChromeDriverService.java
Debugclass for debug mode checkingDebug.isDebugAll()to enable verbose loggingtrueinstead ofproperty value
EdgeDriverService.java
Enable verbose logging when SE_DEBUG is setjava/src/org/openqa/selenium/edge/EdgeDriverService.java
Debugclass for debug mode checkingDebug.isDebugAll()to enable verbose loggingtrueinstead ofproperty value
GeckoDriverService.java
Set Firefox debug level when SE_DEBUG is enabledjava/src/org/openqa/selenium/firefox/GeckoDriverService.java
Debugclass for debug mode checkingDEBUGwhenSE_DEBUGis enabledLoggingOptions.java
Route grid logging to stderr in debug modejava/src/org/openqa/selenium/grid/log/LoggingOptions.java
Debugclass for debug mode checkingFINEwhenSE_DEBUGis enabledSE_DEBUGis activeRemoteWebDriver.java
Initialize debug logger on RemoteWebDriver loadjava/src/org/openqa/selenium/remote/RemoteWebDriver.java
Debug.configureLogger()to set up JUL handler for debug outputDriverService.java
Route driver service output to stderr in debug modejava/src/org/openqa/selenium/remote/service/DriverService.java
Debugclass for debug mode checkingSE_DEBUGis enabledLOG_STDERRas default location instead ofLOG_NULLin debug mode