14

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

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

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

rghome
  • 8,529
  • 8
  • 43
  • 62
Alexey Kulikov
  • 1,097
  • 1
  • 14
  • 38

3 Answers3

22

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);
Christian Neverdal
  • 5,655
  • 6
  • 38
  • 93
Hery
  • 7,443
  • 9
  • 36
  • 41
  • 1
    I'm using the same config file but it doesn't work, the ghost driver still print all the INFO log on the screen. This is my config lines: phantomJSCaps.setCapability(PhantomJSDriverService.PHANTOMJS_GHOSTDRIVER_CLI_ARGS, "--webdriver-loglevel=NONE"); phantomJSCaps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, "/usr/lib/phantomjs/bin/phantomjs"); – tribbloid Jun 16 '14 at 08:28
  • I found this in the source code: * NOTE: This is useful only when used together with PhantomJSDriverService#PHANTOMJS_GHOSTDRIVER_PATH_PROPERTY. * So it is not supposed to be used like this. But is there way to set the PHANTOMJS_GHOSTDRIVER_PATH_PROPERTY? – tribbloid Jun 16 '14 at 08:35
  • Somehow it works for me without setting that property. However I see the way to set it [here](https://github.com/detro/ghostdriver/issues/243). Maybe you can try it out. – Hery Jun 21 '14 at 12:38
  • @Hery - How do I do this in Ruby ? – stack1 Jan 23 '15 at 18:54
  • This one works for me with Phantoms js 1.2 and Selenium 2.53 version. – Bằng Rikimaru Aug 14 '17 at 11:56
3

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:

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

Seems that GhostDriver should be be updated to not log when

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

is used.

Prasad Khode
  • 6,602
  • 11
  • 44
  • 59
jsdevel
  • 1,539
  • 1
  • 12
  • 8
-2
PhantomJSDriverService service = new PhantomJSDriverService.Builder()
        .usingPhantomJSExecutable(new File(VariableClass.phantomjs_file_path))
        .withLogFile(null)
        .build();
Prasad Khode
  • 6,602
  • 11
  • 44
  • 59