msew wrote:

> could you post that? :-)

i've posted a code fragment instead. i've actually made a fair amount of progress 
(aiming to be able to use log4j for webapp-savy logging) but i'm not very happy with 
the code. it works for me but i can't easily get the hooks i need to subclass log4j 
without a kludge and is generally pretty inelegant and a bit hacked
together.

>
> Questions:
>
> if you want a specific servlet container to load up a DOMConfigurator that will tell 
>log4j how to log things, what do you need to do?

>
>
> ie could you just make a singleton or something that is loaded when a servlet "runs" 
>and that can hold the log4j configuration stuff.  (ie in normal apps you make the 
>DOMConfigurator in the main method.  in a servlet container there really is no main 
>per say.  where do you stick the call to create the DOMConfigurator )
>
> and all of the  cat.info("foo");  will use that Configurator.
>
> certainly all of the paths for where the logs are stored will be relative to some 
>variable (contatiner, container runner, etc etc).  but that is semi secondary to 
>getting a set of servlets up and running using your Appender Config.
>
> it should all jsut work right?  Also where do you stick your config file? the 
>WEB-INF/  WEB_INF/classes   lib/   :-)

i'll answer all your questions together if i may.
my approach is to use a context listener. when the context is created, the listener 
gets an event from tomcat. i store the path (relative to the web app base) in an init 
property of the web app. i then use the code similar to the above to load the 
properties file - the main difference is that i use a custom configurator
which allows me to initialize custom appenders with the context. this means that i can 
appender to the context log (rather than stdout) and that i can use a custom file 
appender which appends to a file relative to the web app base rather than having to 
use an absolute path (much better for portability). using a listener
means that i can also log session events and attribute events. i've found this very, 
very useful in debugging.
i don't know what other people think but i'm not100% happy with this approach. to make 
the code robust would require (small) changes to log4j. you also need a modern version 
of tomcat 4 since 2.3 servlet api compliance is neccessary for the container.

so for the moment, i'd stick with bunging the fragment into the servlet init code.

(if you're dead kean i could probably tidy up some of the other code but i'm not too 
kean about putting what's pretty ropey code under public scrutiny.)

- robert


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

Reply via email to