18

我需要关闭 Marionette/GeckoDriver 日志记录;有什么办法吗?我一直在寻找很多,但我没有得到正确的答案。INFO 日志是:

 1484653905833  geckodriver INFO    Listening on 127.0.0.1:15106
    Jan 17, 2017 5:21:46 PM org.openqa.selenium.remote.ProtocolHandshake createSession
    INFO: Attempting bi-dialect session, assuming Postel's Law holds true on the remote end
    1484653906715   mozprofile::profile INFO    Using profile path C:\Users\vtiger\AppData\Local\Temp\3\rust_mozprofile.7d2LEwDKoE8J
    1484653906720   geckodriver::marionette INFO    Starting browser C:\Program Files\Mozilla Firefox\firefox.exe
    1484653906731   geckodriver::marionette INFO    Connecting to Marionette on localhost:58602
    1484653908388   addons.manager  DEBUG   Application has been upgraded
    1484653908843   addons.manager  DEBUG   Loaded provider scope for resource://gre/modules/addons/XPIProvider.jsm: ["XPIProvider"]
    1484653908846   addons.manager  DEBUG   Loaded provider scope for resource://gre/modules/LightweightThemeManager.jsm: ["LightweightThemeManager"]
    1484653908852   addons.manager  DEBUG   Loaded provider scope for resource://gre/modules/addons/GMPProvider.jsm
    1484653908855   addons.manager  DEBUG   Loaded provider scope for resource://gre/modules/addons/PluginProvider.jsm
    1484653908857   addons.manager  DEBUG   Starting provider: XPIProvider
    1484653908857   addons.xpi  DEBUG   startup
    1484653908858   addons.xpi  INFO    SystemAddonInstallLocation directory

如何关闭此日志记录?

4

7 回答 7

26

您可以通过系统属性将它们发送到 /dev/null 来禁用日志,如下所示:

System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE,"/dev/null");

return new FirefoxDriver();
于 2017-09-19T20:20:12.457 回答
6

Windows 和 Linux 上的工作解决方案。

# python 3

# windows
PATH_TO_DEV_NULL = 'nul'
FIREFOX_DRIVER_PATH = 'D:\\path\\to\\geckodriver.exe'

# linux
PATH_TO_DEV_NULL = '/dev/null'
FIREFOX_DRIVER_PATH = '/path/to/geckodriver'

# start browser
driver = webdriver.Firefox(executable_path=FIREFOX_DRIVER_PATH,
                           service_log_path=PATH_TO_DEV_NULL)

于 2019-07-10T15:44:55.960 回答
3

尝试了以下代码,但没有奏效。看起来像一个bugselenium 3.0

    LoggingPreferences pref = new LoggingPreferences();
    pref.enable(LogType.BROWSER, Level.OFF);
    pref.enable(LogType.CLIENT, Level.OFF);
    pref.enable(LogType.DRIVER, Level.OFF);
    pref.enable(LogType.PERFORMANCE, Level.OFF);
    pref.enable(LogType.PROFILER, Level.OFF);
    pref.enable(LogType.SERVER, Level.OFF);


    DesiredCapabilities desiredCapabilities = DesiredCapabilities.firefox();
    desiredCapabilities.setCapability(CapabilityType.LOGGING_PREFS, pref);

    WebDriver driver = new FirefoxDriver(desiredCapabilities);

    driver.get("https://www.google.com/");
    driver.findElement(By.id("lst-ib")).sendKeys("something");
    Thread.sleep(2000);
    driver.quit();
于 2017-01-17T14:50:57.857 回答
2

这里提出了一个对某些人有效的选项,并使用批处理文件将命令行参数传递给可执行文件。不幸的是,这通常会使额外的进程处于打开状态(geckodriver.exe、cmd.exe),并且目前还没有针对下一个问题提出解决方案......

于 2017-07-03T19:06:12.593 回答
1
  GeckoDriverService gecko = new GeckoDriverService(new File("c:/selenium/geckodriver.exe"), 4444, ImmutableList.of("--log=fatal"), ImmutableMap.of());
  gecko.sendOutputTo(new FileOutputStream("gecko_log.txt"));
  gecko.start();

  FirefoxOptions opts = new FirefoxOptions().setLogLevel(Level.OFF);
  DesiredCapabilities capabilities = opts.addTo(DesiredCapabilities.firefox());
  capabilities.setCapability("marionette", true);
  FirefoxDriver driver = new FirefoxDriver(gecko, capabilities);
于 2017-04-18T09:14:50.773 回答
1

这可能有点hacky,但它可以快速完成工作。鉴于您知道文件的确切位置并在 Linux 上运行代码,您只需 cd 进入该目录并

rm geckodriver.log
ln -s /dev/null geckodriver.log
于 2020-06-17T09:24:56.840 回答
0

service_log_path似乎在python中已被弃用:

driver.py:77: DeprecationWarning: service_log_path has been deprecated, please pass in a Service object

这现在对我有用:

from selenium.webdriver.firefox.service import Service as FirefoxService
from selenium import webdriver

service = FirefoxService(driver_path, log_path='nul') # Disable logs in windows, for linux probably /dev/null

driver = webdriver.Firefox(
    service=service
)
于 2022-02-01T10:32:55.003 回答