[slf4j-user] slf4j logger -> Servlet container log : How to?

Thorbjoern Ravn Andersen ravn at runjva.com
Wed May 12 18:35:33 CEST 2010


Den 12/05/10 06.27, Jacob Kjome skrev:
>
>> Ok. So if I understand this correctly, your approach uses a servlet
>> listener to register all contexts keyed by the last part of their
>> context path, and you tell the appender in question which ServletContext
>> to retrieve and then forward to that logger.
>>
>
> Each webapp that defines the servlet context listener can participate 
> in servlet context logging.  However, how many contexts the the 
> servlet context appender handles depends on how you set up 
> classloading.  If you deploy the log4j-sandbox.jar, along with 
> log4j.jar, in WEB-INF/lib and use child-first classloading, then the 
> servlet context appender will only ever deal with a single context; 
> the current one.  On the other hand, if log4j-sandbox.jar and 
> log4j.jar are shared, e.g., at the container level, then it would 
> handle more context paths.

Ok, the crucial trick is child-first loading and log4j deployments in 
each web container.  Makes sense now.


>> Will this also work with multiple web apps using slf4j, or will they go
>> to the same appender?
>>
>
> It's been a while since I used it or studied it closely, but it should 
> handle as many contexts as you give it.  Note that I've never tried it 
> via SLF4J, only directly using Log4j.
>
> BTW, the way I've used this in the past is either to place the jars in 
> WEB-INF/lib and use child-first classloading or use a logger 
> repository selector.  I always manually configure Log4j after letting 
> the servlet context listener register the context to the appender.  
> Then in Tomcat, for instance, I place log4j.jar in a shared lib 
> location along with log4j.properties, meant for configuring the server 
> to use Log4j, which looks somewhat like below.  So, the server has its 
> own log4j configuration while each webapp has its own configuration.  
> And when my app either logs directly to the servlet context or logs 
> via the servlet context log appender, I have defined exactly where the 
> output goes; to "${catalina.base}/logs/localhost_mycontext.log".
>
> Oh, and I had to follow these instructions to get Tomcat to use Log4j...
> http://tomcat.apache.org/tomcat-6.0-doc/logging.html#log4j
Thank you.  It is a very interesting approach.

-- 

   Thorbjørn Ravn Andersen  "...plus... Tubular Bells!"



More information about the slf4j-user mailing list