Java PhantomJSDriver 禁用控制台中的所有日志

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20181329/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 23:47:21  来源:igfitidea点击:

Java PhantomJSDriver disable all logs in console

javaphantomjsghostdriver

提问by Alexey Kulikov

I'm developing a small console app using Selenium and I need to turn off all logs from it.

我正在使用 Selenium 开发一个小型控制台应用程序,我需要关闭它的所有日志。

I have tried phantomJSDriver.setLogLevel(Level.OFF);but it does not work. I need help.

我试过了,phantomJSDriver.setLogLevel(Level.OFF);但它不起作用。我需要帮助。

How do I disable all logs in console application that is using Selenium and Phantomjs (GhostDriver)?

如何禁用使用 Selenium 和 Phantomjs (GhostDriver) 的控制台应用程序中的所有日志?

采纳答案by Alexey Kulikov

PhantomJSDriverService service = new PhantomJSDriverService.Builder()
        .usingPhantomJSExecutable(new File(VariableClass.phantomjs_file_path))
        .withLogFile(null)
        .build();

回答by Hery

This one works for me.

这个对我有用。

DesiredCapabilities dcap = new DesiredCapabilities();
String[] phantomArgs = new  String[] {
    "--webdriver-loglevel=NONE"
};
dcap.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, phantomArgs);
PhantomJSDriver phantomDriver = new PhantomJSDriver(dcap);

回答by jsdevel

Looking at the source files of org.openqa.selenium.phantomjs.PhanomJSDriverService while debugging, I discovered that it's actually ignoring documented log levels for ghostdriver itself. Doing this disables the bulk of ghostdriver output:

在调试时查看 org.openqa.selenium.phantomjs.PhanomJSDriverService 的源文件,我发现它实际上忽略了 ghostdriver 本身的记录日志级别。这样做会禁用大部分 ghostdriver 输出:

Logger.getLogger(PhantomJSDriverService.class.getName()).setLevel(Level.OFF);

Seems that GhostDriver should be be updated to not log when

似乎应该更新 GhostDriver 以在以下情况下不登录

phantomJSCaps.setCapability(PhantomJSDriverService.PHANTOMJS_GHOSTDRIVER_CLI_ARG??S, "--webdriver-loglevel=NONE");  

is used.

用来。