How to turn off the Marionette/gecko driver logs in selenium 3
Asked Answered
T

7

19

I need to turn off the Marionette/GeckoDriver logging; is there is any way to do that? I've been searching a lot, but I am not getting the proper answer. The INFO logs were:

 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

How do I turn off this logging?

Threesquare answered 17/1, 2017 at 12:6 Comment(1)
Possible duplicate of How do I disable Firefox logging in Selenium using Geckodriver?Tatro
P
3

Tried the following code, but didn't work. Seems like a bug in selenium 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();
Purebred answered 17/1, 2017 at 14:50 Comment(4)
Even I tried the same. I think it is a bug in gecko driver, will wait for the next release.Threesquare
I suppose that is the same of: firefoxOptions.setLogLevel(Level.OFF); capabilities.setCapability("moz:firefoxOptions", firefoxOptions);Limerick
Is there a bug report? Has this been fixed?Unpretentious
As of 2022, still doesn't work.Slave
S
26

You can disable the logs by sending them to /dev/null via a system property like so:

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

return new FirefoxDriver();
Spirant answered 19/9, 2017 at 20:20 Comment(4)
This worked for me, even with omitting the DRIVER_USE_MARIONETTE line 👍Solfa
Using arquillian i only needed last propertyThereunder
How would I set it to log level warn?Unpretentious
name 'System' is not definedUnstable
B
6

Working solution on Windows and 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)

Berezniki answered 10/7, 2019 at 15:44 Comment(0)
P
3

Tried the following code, but didn't work. Seems like a bug in selenium 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();
Purebred answered 17/1, 2017 at 14:50 Comment(4)
Even I tried the same. I think it is a bug in gecko driver, will wait for the next release.Threesquare
I suppose that is the same of: firefoxOptions.setLogLevel(Level.OFF); capabilities.setCapability("moz:firefoxOptions", firefoxOptions);Limerick
Is there a bug report? Has this been fixed?Unpretentious
As of 2022, still doesn't work.Slave
S
2

One option that has worked for some is proposed here, and uses a batch file to pass in command line arguments to the executable. Unfortunately, this oftentimes leaves extra processes open (geckodriver.exe, cmd.exe) and no solution to this next problem has been proposed as of yet...

Subphylum answered 3/7, 2017 at 19:6 Comment(0)
B
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);
Breaking answered 18/4, 2017 at 9:14 Comment(0)
R
1

This might be a bit hacky but it can quickly get the job done. Given that you know the exact location of your file and you run your code on Linux you can just cd into that dir and

rm geckodriver.log
ln -s /dev/null geckodriver.log
Remonstrate answered 17/6, 2020 at 9:24 Comment(0)
R
0

service_log_path seems to be deprecated in python:

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

This worked for me now:

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
)
Risteau answered 1/2, 2022 at 10:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.