> From: removeps-gro...@yahoo.com [mailto:removeps-gro...@yahoo.com]
> Subject: RE: How to have multiple loggers with shared code
> also using the logger?
>
> Why is it what I'm trying to do not working though?  It seems
> that my MyLog.getLogger function does find the correct logger
> name, and that Logger.getLogger() is always using the the
> first log4j.properties that was found.

Because of the classloading hierarchy.  Once the logger is initialized with the 
common classloader, everybody uses that one.

> Yeah, I had tried something like this, namely to have a class
> AbstractMyLog in the common folder, and a class MyLog in each
> of the webapps that derives from AbstractMyLog so as to
> minimize code changes.

Don't do that.  Keep just one copy of the source somewhere, just have your 
packaging script put the .class file in the webapp package.  No need to have an 
abstract class or subclasses.

> (1) Pass a logger from the webapp to the common code -- ie.
> to add a Logger argument to all the functions in the common
> code, but this sounds tedious.

That's the cost of keeping things isolated, which is a worthwhile goal.

> (2) In each webapp have a filter that sets a thread local
> variable like ThreadLocal<Logger> threadLogger.

Just make sure you clear the ThreadLocal on *every* possible exit path out of 
your request processing.  If you don't, you will have memory leaks in PermGen 
causing it to fill up as webapps are redeployed.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY 
MATERIAL and is thus for use only by the intended recipient. If you received 
this in error, please contact the sender and delete the e-mail and its 
attachments from all computers.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to