You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Scott Heaberlin <he...@yahoo.com> on 2003/02/19 00:11:35 UTC

Multiple application log files

Hello all - 

I am new to the log4j users list, so forgive me if I
am asking something answered many times before. I did
search the list archives before sending this, and
didn't see any matches to my search but I realize I
simply may have searched on the wrong queries...

My question is as follows:

We recently decided to use Log4J for our website
application logging.  Here is what I am looking to do:

We have several separate "applications" which use both
application specific code as well as code in shared
jar/class libraries.  The behavior we'd like is to
have all code executed by application X to go to, say,
X.log while all code executed by application Y to go
to Y.log.  

For example, application A executes code in
com.foo.SharedClass which logs to what I believe is
the root logger ( Logger.getLogger(SharedClass.class)
).  Application A must log to A.log, including all
logging from A specific classes as well as logging
from shared code executed during A.  Application B, on
the other hand, must log in the same manner to B.log,
including B specific code and shared code logging
output during the course of B's execution.

All in all, a fairly simple concept.  But here are the
restrictions:

1) Our applications are not in standard J2EE web-app
structure (webapps\appName\WEB-INF, web.xml, etc). 
Basically what we refer to as a separate application
is treated by the server as merely a different virtual
subdirectory.  So, we don't have the luxury of a
1-to-1 app to subdir ratio (and therefore 1-to-1 app
to log file).

2) If we can accomplish this via configuration file,
we must use a *single* configuration file for all
apps.  I realize that if each "app" (each having its
own startup servlet for intialization) could use
separate log4j config files each containing the
correct log file location, but we are limited to a
single config file.

Our original thought was to create named Loggers
(Logger.getLogger("applicationA")) when each app's
startup servlet executes init(), but we weren't sure
how the common code would use these loggers.  I have
been reading about the NDC/MDC classes and their
ability to automatically "tag" each log statement in a
particular path of execution for later ease of
differentiation.  Obviously we could use
NDC.push("application_A") calls in each page/servlet
of application A, but this alone doesn't achieve our
goal of having separate logs per application. 
Separate appenders can output to different places via
different methods, but can we somehow specify which
appender to use through each execution context?

Any thoughts/links/RTFMs are much appreciated.


Sincerely,

Scott Heaberlin



__________________________________________________
Do you Yahoo!?
Yahoo! Shopping - Send Flowers for Valentine's Day
http://shopping.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org