Disable log trace in Marionette driver

拥有回忆 提交于 2019-12-04 11:22:10

Firefox is supposed to have an option to set the logging level for Marionette in the about:config property marionette.logging, but this apparently is not present in builds up to and including 47.

Apparently Marionette is not officially supported in build 47, which is unfortunate because FirefoxDriver also no longer works on this build either. Currently the only supported options are to downgrade (and use FirefoxDriver) or wait for updates.

It is theorized that this will be fixed in 47.0.1 or 48 and might already be in the nightlies.

Source: https://github.com/mozilla/geckodriver/issues/89

Michael Medina

You can use the following lines of code to not display the marionette logs:

System.setProperty("webdriver.gecko.driver","src/main/resources/drivers/geckodriver.exe"); 
System.setProperty(FirefoxDriver.SystemProperty.DRIVER_USE_MARIONETTE,"true"); 
System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE,"/dev/null");
return new FirefoxDriver();

Here are all the ways I've seen to do it online, the only part that seems to do ANYTHING AT ALL is setting the browser log file to /dev/null :(

            // ----------- BEGIN NIGHTMARISH AMOUNT OF CODE TO SET THE LOG LEVEL ------------
            boolean detailedLogs = false;

            File profileDirectory = new File(Settings.FireFoxProfilePath);
            System.setProperty("webdriver.gecko.driver", "Drivers/geckodriver-linux64");
            //System.setProperty("webdriver.gecko.driver","src/main/resources/drivers/geckodriver.exe");
            if (!detailedLogs) {
                System.setProperty(FirefoxDriver.SystemProperty.DRIVER_USE_MARIONETTE, "true");
                System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE, "/dev/null");
            }
            FirefoxProfile profile = null;
            FirefoxOptions options = new FirefoxOptions();
            if (profileDirectory.exists()) {
                profile = new FirefoxProfile(profileDirectory);
                profile.setPreference("marionette.log.level", detailedLogs?"trace":"warn");
                profile.setPreference("marionette.logging", detailedLogs);
                options.setProfile(profile);
            }
            options.setLogLevel(FirefoxDriverLogLevel.WARN);
            LoggingPreferences logs = new LoggingPreferences();
            logs.enable(LogType.BROWSER, detailedLogs? Level.ALL : Level.WARNING);
            logs.enable(LogType.CLIENT, detailedLogs? Level.ALL : Level.WARNING);
            logs.enable(LogType.DRIVER, detailedLogs? Level.ALL : Level.WARNING);
            logs.enable(LogType.PERFORMANCE, detailedLogs? Level.ALL : Level.WARNING);
            logs.enable(LogType.PROFILER, detailedLogs? Level.ALL : Level.WARNING);
            logs.enable(LogType.SERVER, detailedLogs? Level.ALL : Level.WARNING);
            //LEGACY: DesiredCapabilities desiredCapabilities = DesiredCapabilities.firefox();
            //desiredCapabilities.setCapability(CapabilityType.LOGGING_PREFS, logs);
            options.setCapability(CapabilityType.LOGGING_PREFS, logs);
            options.addPreference("extensions.logging.enabled", false);
            options.addPreference("marionette.log.level", detailedLogs?"trace":"warn");
            options.addPreference("marionette.logging", detailedLogs); // from https://github.com/mozilla/geckodriver/issues/89
            // ----------- END NIGHTMARISH AMOUNT OF CODE TO SET THE LOG LEVEL ------------
            driver = new FirefoxDriver(options);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!