5

I have been trying to disable DEBUG message to console, but no matter what I do, it still display on the console . I need to find a way to disable the constant logging of the HTTP request and response on the console . Code used :


System.setProperty(ChromeDriverService.CHROME_DRIVER_SILENT_OUTPUT_PROPERTY, "true");
java.util.logging.Logger.getLogger("org.openqa.selenium").setLevel(Level.SEVERE);
HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
 

   chromePrefs.put("profile.default_content_settings.popups", 0);
    chromePrefs.put("download.default_directory", downloadPath);
    ChromeOptions options = new ChromeOptions();
    options.setExperimentalOption("prefs", chromePrefs);

    options.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
    options.setCapability(ChromeOptions.CAPABILITY, options);
    // options.setCapability(ChromeOptions.CAPABILITY, options);
    LoggingPreferences logPrefs = new LoggingPreferences();
    logPrefs.enable(LogType.PERFORMANCE, Level.ALL);
    options.addArguments("--disable-logging");
    options.addArguments("--log-level=3");
    options.addArguments("--silent");
    options.setCapability( "goog:loggingPrefs", logPrefs );
    options.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
    options.setAcceptInsecureCerts(true);
    System.out.println("Launching Google Chrome Browser");
    //ChromeDriverManager.getInstance(CHROME).setup();
    WebDriverManager.chromedriver().setup();
    //   options.merge(cap);



   driver = new ChromeDriver(options);
      
  driver.manage().timeouts().implicitlyWait(TimeOut,TimeUnit.SECONDS);
    driver.manage().window().maximize();

on console

Request DefaultHttpRequest(decodeResult: success, version: HTTP/1.1)
POST /session HTTP/1.1
User-Agent: selenium/4.0.0 (java windows)
Content-Length: 1259
Content-Type: application/json; charset=utf-8
host: localhost:61670
accept: */*

Response DefaultHttpResponse(decodeResult: success, version: HTTP/1.1)
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
cache-control: no-cache
content-length: 788

[AsyncHttpClient-1-2] DEBUG org.asynchttpclient.netty.channel.ChannelManager - Adding key: http://localhost:61670 for channel [id: 0xaa9e94af, L:/127.0.0.1:63133 - R:localhost/127.0.0.1:61670]
[AsyncHttpClient-1-3] DEBUG org.asynchttpclient.netty.channel.NettyConnectListener - Using new Channel '[id: 0x60845110, L:/127.0.0.1:63145 - R:localhost/127.0.0.1:63134]' for 'GET' to '/json/version'
 [AsyncHttpClient-1-3] DEBUG org.asynchttpclient.netty.handler.HttpHandler - 

Request DefaultFullHttpRequest(decodeResult: success, version: HTTP/1.1, content: EmptyByteBufBE)
GET /json/version HTTP/1.1
User-Agent: selenium/4.0.0 (java windows)
host: localhost:63134
accept: */*

Response DefaultHttpResponse(decodeResult: success, version: HTTP/1.1)
HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
content-length: 424

I need to find a way to remove the debug message during execution , this occur on selenium 4.0

Nandan A
  • 2,702
  • 1
  • 12
  • 23
NFT Team
  • 81
  • 1
  • 2

3 Answers3

1

Solution – Empty Configuration To fix it, create an empty configuration file as logback-test.xml, and save it under $project/src/test/resources

$project/src/test/resources/logback-test.xml

Visit the below website for more reference https://mkyong.com/logging/logback-disable-logging-in-unit-test/

0

Simply change the logging level:

java.util.logging.Logger.getLogger("org.openqa.selenium").setLevel(Level.SEVERE);

to:

java.util.logging.Logger.getLogger("org.openqa.selenium").setLevel(Level.INFO);

or some lower level than SEVERE.

See https://docs.oracle.com/javase/7/docs/api/java/util/logging/Level.html

pburgr
  • 1,722
  • 1
  • 11
  • 26
  • Good catch....! but in documents for Info also it is saying "Typically INFO messages will be written to the console or its equivalent." may be as you suggested he needs to select another low level. – Nandan A Nov 29 '21 at 13:15
  • i have used java.util.logging.Logger.getLogger("org.openqa.selenium").setLevel(Level.WARNING); but still the debug message is still present – NFT Team Nov 30 '21 at 05:27
  • Then simply try lower and lower value. – pburgr Nov 30 '21 at 06:42
  • 2
    i have used java.util.logging.Logger.getLogger("org.openqa.selenium").setLevel(Level.SEVERE); and java.util.logging.Logger.getLogger("org.openqa.selenium").setLevel(Level.OFF); but still the debug message is still present – NFT Team Nov 30 '21 at 08:21
  • Any solution to remove the DEBUG level logs ? – Dhaval Atri Nov 29 '22 at 09:20
0

Neet to set the logs level as ERROR/WARN/INFO. Please use the below code in your project which is being used to run the chrome driver (End project) from where you are running.

((ch.qos.logback.classic.Logger)LoggerFactory.getLogger("org.asynchttpclient.netty")).setLevel(ch.qos.logback.classic.Level.WARN);
Ankit Gupta
  • 776
  • 5
  • 12