1

My IRC bot sends the statistics of a video when a YouTube link is posted to the channel. But I get warnings in a huge number and they annoy me and just clutter my console:

Sep 01, 2014 6:09:29 PM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler error
WARNUNG: CSS error: 'https://s.ytimg.com/yts/cssbin/www-core-vfl0pJopz.css' [1:41191] Fehler in Style-Regel. (Ungültiger Token "*". Erwartet wurde einer von: <EOF>, <S>, <IDENT>, "}", ";".)
Sep 01, 2014 6:09:29 PM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler warning
WARNUNG: CSS warning: 'https://s.ytimg.com/yts/cssbin/www-core-vfl0pJopz.css' [1:41191] Ignoriere die folgenden Deklarationen in dieser Regel.

I'd like to turn them off, and have tried to add this code to my main method:

java.util.logging.Logger.getLogger("com.gargoylesoftware").setLevel(Level.OFF);

But to no avail. I am using Selenium to get the results using this code:

String[] args = Utilities.toArgs(event.getMessage()); //this is the message sent, split by a space
        String link = null;
        boolean shortLink = false;
        WebDriver driver = new HtmlUnitDriver();
        String title = "No value";
        String duration = "No value";
        String views = "No value";
        String likes = "No value";
        String dislikes = "No value";
        String date = "No value";
        String uploader = "No value";

        for(String s : args)
        {
            if(s.contains("www.youtube.com/watch"))
            {
                if(s.contains("v="))
                    link = "http://www.youtube.com/watch?v=" + s.split("v=")[1].substring(0, 11) + "/";
                else
                {
                    Utilities.chanMsg(event, "Couldn't find video id!"); //just sending a message to the channel
                    break;
                }
            }
            else if(s.contains("http://youtu.be/"))
            {
                link = s;
                shortLink = true;
                break;
            }
        }

        if(shortLink)
        {
            String videoId = link.split("/")[3];

            link = "www.youtube.com/watch?v=" + videoId;
        }

        //if someone posts the link without a space between the link and the word before it
        if(!link.startsWith("w"))
            link = link.split(":")[1].substring(2);

        //check that the link is really the link needed (main use is when someone posts a word directly after the link without a space inbetween)
        if(link.length() != 35)
        {
            StringBuilder builder = new StringBuilder();
            builder.append(link);
            builder.delete(35, link.length());
            link = builder.toString();
        }

        //make sure that the links starts with "http://"
        if(!link.startsWith("http://"))
            link = "http://" + link;

        driver.get(link);

        try
        {
            title = driver.findElement(By.xpath("//meta[@itemprop='name']")).getAttribute("content");
        }
        catch(NoSuchElementException e){}

        try
        {
            duration = resolveDuration(driver);
        }
        catch(NoSuchElementException e){}

        try
        {
            views = driver.findElement(By.xpath("//div[@class='watch-view-count']")).getText();
        }
        catch(NoSuchElementException e)
        {
            views = driver.findElement(By.xpath("//span[@class='watch-view-count yt-uix-hovercard-target']")).getText().split("Views")[0];
        }

        try
        {
            likes = driver.findElement(By.xpath("//button[@id='watch-like']/span[@class='yt-uix-button-content']")).getText();
        }
        catch(NoSuchElementException e){}

        try
        {
            dislikes = driver.findElement(By.xpath("//button[@id='watch-dislike']/span[@class='yt-uix-button-content']")).getText();
        }
        catch(NoSuchElementException e){}

        try
        {
            date = driver.findElement(By.xpath("//p[@id='watch-uploader-info']/strong")).getText().split("on")[1];
        }
        catch(NoSuchElementException e){}

        try
        {
            uploader = driver.findElement(By.xpath("//div[@class='yt-user-info']/a")).getText();
        }
        catch(NoSuchElementException e){}

        driver.close();

So how would I be able to suppress the warnings sent to the console?

bl4ckscor3
  • 11
  • 1
  • 4

1 Answers1

0

You can handle this using Capabilities

Though these capabilities are browser specific.Say for firefox it would be like webdriver.log.driver. For more details you can refer the link below.

Desired Capabilities

More details on logging in Selenium Webdriver can be found here : Logging in Selenium

UPDATED : If you are using HtmlUnitDriver for which no browser is opened, You have to use your own logging system with proper configuration. You can go either for Log4j or SimpleLog library. In case you use log4j, just add this line in a file commons-logging.properties

 org.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger

and keep the log4j.xml in the same folder where property file is kept.Normally the /src/main/resources: folder in case its a Maven Project.Then in log4j.xml you can configure your logging level as per your need.

Abhishek_Mishra
  • 4,551
  • 4
  • 25
  • 38
  • Thank you, but I'm using HtmlUnitDriver as you can see in the example and I can't find the logger for that driver. (Using the FirefoxDriver and webdriver.log.driver works, but I can't use the FirefoxDriver when the Bot is on a VPS). – bl4ckscor3 Sep 02 '14 at 14:14