webmetrics / browsermob-proxy

NOTICE: this project has been forked and is being maintained at https://github.com/lightbody/browsermob-proxy
https://github.com/lightbody/browsermob-proxy
Apache License 2.0
233 stars 780 forks source link

Browsermob should not reconfigure the root logger automatically #77

Closed scottmcmaster closed 11 years ago

scottmcmaster commented 11 years ago

See the static ctor in Log.java. This makes it a little hard to set up, say, a FileHandler in a program that is using Browsermob.

lightbody commented 11 years ago

I'm a bit of a Java logging n00b, so please feel free to submit a pull request with a better way to approach this. I wrote the logging like it is assuming that most people won't be embedding the program and instead will treat it like a simple command line program that gets piped through some more comprehensive logging setup.

hiansh commented 11 years ago

I am using browsermob in embedded mode. I have never been able to successfully configure the browserlog logs. If there is a way to do it kindly share.

scottmcmaster commented 11 years ago

Yes, I see browsermob most often embedded to work around everybody's favorite WebDriver bug 141. Anyway, hopefully you can do something like this:

new org.browsermob.proxy.util.Log();

InputStream in = null;
try {
    in = MyUtilsClass.class.getResourceAsStream("/logging.properties");
    LogManager.getLogManager().readConfiguration(in);
} catch (IOException ex) {
    System.err.println("WARNING: Logging not configured (console output only)");
} finally {
  try { in.close(); } catch (Exception e) {}
}

The sequence of event is: First, force browsermob's Log to statically initialize, during which it blows away any existing logging configuration that may have been set up. Second, explicitly re-read your own logging configuration. It is satisfactory for me, anyway, until I have time to make a better suggestion to Patrick.

hiansh commented 11 years ago

Thanks @xskt !!

lightbody commented 11 years ago

This is fixed in the primary development line, which is at https://github.com/lightbody/browsermob-proxy. Basically, I removed the static line and moved it in to Main.java, which is where standalone mode runs. So if you're embedding, I no longer do any funky stuff with logging. Hope that helps. If you have more problems, please open a new ticket in that other project. Thanks!