On Mon, Feb 7, 2011 at 10:15 AM, Gian Marco Gherardi
<[email protected]> wrote:
> I've not used SLF4JBridgeHandler.install() because it binds to the root
> logger, but i only want to redirect Guice logging.
> The implementation of the install method is almost the same as the snippet,
> so this should work as expected (and it works).

Ah, my mistake, I should have read more carefully. In this case, what
you do does work, but I don't think you need the interaction with the
LogManager; the following *should* be sufficient:

  Logger.getLogger("com.google.inject").addHandler(new SLF4JBridgeHandler();

The Logger factory method ensures that the logger is registered.

That said, if I were to do this I would not do it in code at all, but
instead use the logging.properties configuration file to install the
handler:

  com.google.inject.handlers = org.slf4j.bridge.SLF4JBridgeHandler

IMO this allows you to more easily configure your logging behavior for
different environments. It does assume you want to replace the default
handlers instead of adding to default handlers, as your code does
above.

> I understand that SLF4J is not related to Guice, but i suppose that this is
> a common scenario when integrating Guice with anything else

It is for me, but I think the Guice team is right omit this, because
without co-ordination from SLF4J, their documentation would eventually
not be in sync, and wrong documentation is worse than none. In this
case, there's nothing Guice specific about configuring SLF4J; even the
ContextListener approach is stock Servlets, not specific to Guice at
all.

Good luck!

-- 
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-guice?hl=en.

Reply via email to