[slf4j-user] J2EE logging and loggers serialization
Claude Brisson
claude at renegat.net
Sun Sep 13 11:53:07 CEST 2015
Hi.
The ServletContext backend looked like an abandoned project, and didn't
support serialization. So I forked it and added several features, including:
- Zero-configuration: adding webapp-slf4j-logger.jar to the webapp
will enable a default logging, which includes HTTP request IP addresses
as a prefix.
- Custom format, supporting mapped diagnostic contexts.
- Support for serialization and deserialization.
You can see the result here:
http://arkanovicz.github.io/webapp-slf4j-logger/
When the J2EE container itself uses SLF4J, the warning about multiple
bindings will show up, but if the J2EE container does child-first class
loading in the webapp (which most do), everything will be fine.
I'm still curious about webbapp login common practices: the main
advantage of using the ServletContext logger is that you don't have to
worry about the physical location of the log file, which is quite handy
when you're packaging a webapp meant to be deployed on different
environments. For instance, configuring logback to log -let say- in
/WEB-INF/log/ involves setting up a JNDI selector and tweaking the J2EE
container configuration (as described in logbak manual chapter 9), which
is not always possible.
--
Claude
On 21/08/2015 17:18, Claude Brisson wrote:
> Hi.
>
> I have some questions about using slf4j in a J2EE context:
>
> 1) I see there is a ServletContext back-end here:
> https://github.com/pmahoney/slf4j-servletcontext
> but it doesn't seem referenced on the slf4j website, although it looks
> like the only way to have the webapp rely on the container logger.
> Does it mean that it's a standard behavior to ignore the container logger?
>
> 2) I read in the FAQ: "As of SLF4J version 1.5.3, logger instances
> survive serialization. Thus, serialization of the host class no longer
> requires any special action, even when loggers are declared as
> instance variables."
> Would this still be true when using the slf4j-servletcontext back-end?
> Let say I want to put a logger as a session attribute. Since the
> servlet context initialization may happen *after* sessions
> de-serialization, I have some doubts about it...
>
> Thanks,
>
> Claude
>
>
>
> _______________________________________________
> slf4j-user mailing list
> slf4j-user at qos.ch
> http://mailman.qos.ch/mailman/listinfo/slf4j-user
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.qos.ch/pipermail/slf4j-user/attachments/20150913/8f94ba74/attachment.html>
More information about the slf4j-user
mailing list