【问题标题】:How to hide unessesary Selenium debug messages from console in java如何在 Java 中隐藏来自控制台的不必要的 Selenium 调试消息
【发布时间】:2020-06-19 10:12:01
【问题描述】:

我正在使用 Intellij 和 jdk 14 来构建 seleninum 测试。我只希望控制台输出为测试报告、结果或错误。我尝试了许多在 google 或 stackoverflow 上找到的方法,例如设置日志级别、grep 控制台,但这些消息仍然出现。有没有办法解决这个问题?这是输出:

16:44:14.551 [main] DEBUG io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedByteBuffersPerChunk: 1023
16:44:14.559 [main] DEBUG io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled
16:44:14.560 [main] DEBUG io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0
16:44:14.560 [main] DEBUG io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384
Starting ChromeDriver 83.0.4103.39 (ccbf011cb2d2b19b506d844400483861342c20cd-refs/branch-heads/4103@{#416}) on port 7431
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
16:44:15.681 [Forwarding newSession on session null to remote] DEBUG io.netty.channel.DefaultChannelId - -Dio.netty.processId: 17484 (auto-detected)
16:44:15.683 [Forwarding newSession on session null to remote] DEBUG io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false
16:44:15.683 [Forwarding newSession on session null to remote] DEBUG io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false
16:44:15.689 [Forwarding newSession on session null to remote] DEBUG io.netty.util.NetUtil - Loopback interface: lo (Software Loopback Interface 1, 127.0.0.1)
16:44:15.689 [Forwarding newSession on session null to remote] DEBUG io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200
16:44:15.696 [Forwarding newSession on session null to remote] DEBUG io.netty.channel.DefaultChannelId - -Dio.netty.machineId: fc:aa:14:ff:fe:e6:1d:11 (auto-detected)
16:44:15.758 [AsyncHttpClient-3-1] DEBUG io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true
16:44:15.758 [AsyncHttpClient-3-1] DEBUG io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true
16:44:15.759 [AsyncHttpClient-3-1] DEBUG io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@3d005e97
16:44:15.777 [AsyncHttpClient-3-1] DEBUG org.asynchttpclient.netty.channel.NettyConnectListener - Using new Channel '[id: 0x09b55496, L:/127.0.0.1:54163 - R:localhost/127.0.0.1:7431]' for 'POST' to '/session'
16:44:15.829 [AsyncHttpClient-3-1] DEBUG io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096
16:44:15.829 [AsyncHttpClient-3-1] DEBUG io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2
16:44:15.829 [AsyncHttpClient-3-1] DEBUG io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16
16:44:15.830 [AsyncHttpClient-3-1] DEBUG io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8
16:44:20.511 [AsyncHttpClient-3-1] DEBUG org.asynchttpclient.netty.handler.HttpHandler - 

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

【问题讨论】:

    标签: java selenium


    【解决方案1】:

    您真正需要做的是在控制台日志处理程序(负责将所有日志消息打印到控制台)上设置日志级别。但是,在使用 BasicConfigurator 时这样做会非常棘手,您最好在属性文件中指定日志配置(这样更灵活)。

    我建议您通过log4j logging configuration tutorial 工作 - 这将帮助您准确地组合您想要的配置,并且应该证明您的时间投资是值得的。但是,如果您想快速完成此操作,请尝试将以下内容添加到文件 log4j.properties (example taken from here):

    # Root logger option
    log4j.rootLogger=INFO, stdout
    
    # Direct log messages to stdout
    log4j.appender.stdout=org.apache.log4j.ConsoleAppender
    log4j.appender.stdout.Target=System.out
    log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
    log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
    

    然后更改您的代码以执行以下操作:

    Properties props = new Properties();
    props.load(new FileInputStream("/my/path/to/log4j.properties"));
    PropertyConfigurator.configure(props);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-06-25
      • 2016-04-18
      • 2022-06-30
      • 2014-02-01
      • 1970-01-01
      • 2020-10-22
      • 2020-11-22
      • 1970-01-01
      相关资源
      最近更新 更多