You could set an MDC with the servlet name and then filter the logs.

James Stauffer


-----Original Message-----
From: Shapira, Yoav [mailto:[EMAIL PROTECTED] 
Sent: Friday, June 11, 2004 12:59 PM
To: Log4J Users List
Subject: RE: Separate log file per servlet



Hi,

>1) What is the reason for setting additivity to false in this scenario
>2) does additivity need to be set to false for each appender in this 
>scenario, or only the first?

In my example, I set additivity to false for all the appenders, because I
didn't know what was in the rest of his configuration file.  It's better to
over-isolate than get multiple copies of logging statements IMHO, but it's
certainly not a requirement, and certainly more details need to be known in
order to establish if that's a good approach for this scenario.

As for configuring log4j: do it once, in a ServletContextListener's
contextInitialized method, not from a servlet.

As for the shared class using whatever appender its calling class is
using: ack, that's a bit of a pain.  Logging Domains would help here, but
that's log4j 1.3 ;)  You can also do this fairly nicely with some Aspects
(as in AOP Aspects).  You could pass the name of the calling class, the
calling class itself, or the Logger object itself, to all methods in the
shared class.  That's simple and would work, though it's a bit ugly.  You
could figure out the calling class name using stack trace tricks, but that's
costly from a performance perspective.  I don't know what I'd pick in this
scenario, but then again I wouldn't be in this scenario to start with
because I really dislike the "every component [or class, or whatever] goes
into its own log destination" approach -- I prefer sending everything to one
destination and then filtering/viewing using a good tool like Chainsaw or
emacs ;)

Yoav Shapira



This e-mail, including any attachments, is a confidential business
communication, and may contain information that is confidential, proprietary
and/or privileged.  This e-mail is intended only for the individual(s) to
whom it is addressed, and may not be saved, copied, printed, disclosed or
used by anyone else.  If you are not the(an) intended recipient, please
immediately delete this e-mail from your computer system and notify the
sender.  Thank you.


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

Reply via email to