[snip]
>
> The questions are:
> Is this configuration correct?
Probably not, because you never call the install method on the
SLF4JBridgeHandler. Read the fine documentation at
http://www.slf4j.org/api/org/slf4j/bridge/SLF4JBridgeHandler.html and
bear in mind the performance warning at
http://www.slf4j.org/legacy.html#jul-to-slf4j
> Is there a better way to do this?
Your context listener is an appropriate location to do this, assuming
you are using Guice Servlet as you appear to be.
> Why not including this in Guice documentation?
Because SLF4J is not related to Guice in any way.
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!