Jacob Kjome has pointed us at his log4j init servlet in the past.  It is
really quite full featured and definitely worth taking a look.

http://marc.theaimsgroup.com/?l=log4j-dev&m=103725695000410&w=2

Yoav's point about using the context listeners (requiring Servlet 2.3) is
very valid, and going forward it is a cleaner way to init/shutdown log4j in
the web application context.  If Jacob has not already done it, it might be
useful to break out the relevant portions of his servlet into context
listeners.  But I'll leave that for him to comment.

I would also like to say that I have proposed that we include servlet/web
application support in v1.3 of log4j.  This would include an init servlet,
context listeners, configuration via a servlet, etc.  Jacob has proposed to
include his servlet as a start (<hint>Maybe Jacob would like to lead the
effort...</hint>).  If anyone has other ideas/submissions, we'd like to hear
about them.  We want to make log4j as useful as possible "out of the box" so
that folks don't have to re-invent the wheel each time.

-Mark

> -----Original Message-----
> From: Shapira, Yoav [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, December 12, 2002 5:50 AM
> To: Log4J Users List
> Subject: RE: Log4j Configuration with Servlet
> 
> 
> Howdy,
> While Mr. (?) Lenharcik's suggestion will work, I'd suggest doing it
> slightly differently: use a ServletContextListener and 
> initialize log4j
> in the contextInitialized() method.  That will get called before any
> servlet's init() method.  And the contextDestroyed() method of that
> listener is a great place to shut down log4j gracefully
> (LogManager.shutdown()).  The container is free to unload and 
> reload any
> servlet, including load-on-startup servlets, at any time, so init'ing
> log4j in a servlet is not always optimal.
> 
> >- WEB-INF/webx.ml create an entry to init the servlet while server
> start.
> >One property of this entry is the path to your log4j config-file 
> 
> If you're using a servlet, it's <init-param>, if using a context
> listener it's a context-param.
> 
> >(if your
> >file is in /classes you can use reflection
> >CLASSNAME.class.getRessource("/configfile.lcf")
> 
> Technically speaking, that's not reflection ;)  But it'll work.  For
> people like me who don't like to mix config files and 
> compiled code, you
> can use the
> ServletContext().getResource("/pathtoyourconfigfilefromyourcon
> textroot")
> call to do the same.
> 
> Yoav Shapira
> Millennium ChemInformatics
> 
> --
> To unsubscribe, e-mail:   
> <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail: 
> <mailto:[EMAIL PROTECTED]>
> 

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to