Skip to content

Commit

Permalink
[java] reduce log noise at FINE level (#12866)
Browse files Browse the repository at this point in the history
* [java] reduce log noise at FINE level

* [java] log new session response as a capability if want shorter log messages

* [java] log dump http exchange filter output at lower level

* [java] always use truncation on new session responses
  • Loading branch information
titusfortner authored Oct 6, 2023
1 parent 9b35af2 commit fd0f045
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
18 changes: 14 additions & 4 deletions java/src/org/openqa/selenium/remote/RemoteWebDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -747,15 +747,25 @@ protected void log(SessionId sessionId, String commandName, Object toLog, When w
if (text.length() > 100 && Boolean.getBoolean("webdriver.remote.shorten_log_messages")) {
text = text.substring(0, 100) + "...";
}
} else if (commandName.equals(DriverCommand.NEW_SESSION) && toLog instanceof Response) {
Response responseToLog = (Response) toLog;
try {
Map<String, Object> value = (Map<String, Object>) responseToLog.getValue();
text = new MutableCapabilities(value).toString();
} catch (ClassCastException ex) {
// keep existing text
}
}
// No need to log a screenshot response.

// No need to log a base64 encoded responses.
if ((commandName.equals(DriverCommand.SCREENSHOT)
|| commandName.equals(DriverCommand.ELEMENT_SCREENSHOT))
|| commandName.equals(DriverCommand.ELEMENT_SCREENSHOT)
|| commandName.equals(DriverCommand.PRINT_PAGE)
|| commandName.equals("fullPageScreenshot"))
&& toLog instanceof Response) {
Response responseToLog = (Response) toLog;
Response copyToLog = new Response(new SessionId((responseToLog).getSessionId()));
copyToLog.setValue("*Screenshot response suppressed*");
copyToLog.setStatus(responseToLog.getStatus());
copyToLog.setValue(String.format("*%s response suppressed*", commandName));
copyToLog.setState(responseToLog.getState());
text = String.valueOf(copyToLog);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public class W3CHttpResponseCodec extends AbstractHttpResponseCodec {
public Response decode(HttpResponse encodedResponse) {
String content = string(encodedResponse).trim();
LOG.log(
Level.FINE,
Level.FINER,
"Decoding response. Response code was: {0} and content: {1}",
new Object[] {encodedResponse.getStatus(), content});
String contentType = nullToEmpty(encodedResponse.getHeader(CONTENT_TYPE));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.util.function.Supplier;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.openqa.selenium.internal.Debug;
import org.openqa.selenium.internal.Require;

public class DumpHttpExchangeFilter implements Filter {
Expand All @@ -31,7 +30,7 @@ public class DumpHttpExchangeFilter implements Filter {
private final Level logLevel;

public DumpHttpExchangeFilter() {
this(Debug.getDebugLogLevel());
this(Level.FINER);
}

public DumpHttpExchangeFilter(Level logLevel) {
Expand Down

0 comments on commit fd0f045

Please sign in to comment.