Sounds like you are going to have to setup your appenders dynamically in
each class or delegate the appender construction to an 'AppenderFactory'.
The Factory will take a package name as a parameter. It will construct an
appender for each package and then cache the package name. Additional calls
to the Factory to create an Appender that already exists (is in the cache)
will be ignored.

This is fairly easy. Write the Factory and make a single method call to it
when each class is loaded in a static block. Since you don't know what your
packages are ahead of time, it is counter intuitive to think that you would
have a different appender setup for each one. In this case, you can
externalize the parameters to a properties file that is read by the factory
to determine how to create the appenders.

You don't really need to find out who your caller is. The logging system
does that for you. YOu just need to set up the appenders to filter logging
for only their package and you will have done what you need. Just make sure
that the category uses the package naming heirarchy as suggested in the
docs.

Regards,

Charles

-----Original Message-----
From: Christopher Randall [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, January 02, 2002 5:12 PM
To: Log4J Users List
Subject: RE: Question about setup


Steve,

Thanks for your advice. Unfortunately it doesn't help because I forgot
to mention another requirement: I don't know what the packages are ahead
of time. I will have them in my logging code as a string beforehand
(parse the stack frame of a new Throwable() to get it). Basically, I
figure out who my caller is, and log to the logger set up for the
caller's package.

Chris

-----Original Message-----
From: Steve Ebersole [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, January 02, 2002 4:59 PM
To: Log4J Users List
Subject: Re: Question about setup


Say you have packages com.foo.bar.util and com.foo.bar.system.

########################################################################
####
######
# Define root logger
########################################################################
####
######
log4j.rootLogger=DEBUG, STDOUT

########################################################################
####
######
# Define non-root loggers
########################################################################
####
######
log4j.com.foo.bar.util=DEBUG, UTL_FILE
log4j.additivity.com.foo.bar.util=false

log4j.com.foo.bar.system=DEBUG, SYS_FILE
log4j.additivity.com.foo.bar.system=false

########################################################################
####
######
# Appenders
########################################################################
####
######
log4j.appender.STDOUT=org.apache.log4j.ConsoleAppender
log4j.appender.STDOUT.layout=org.apache.log4j.PatternLayout

log4j.appender.UTL_FILE=org.apache.log4j.DailyRollingFileAppender
log4j.appender.UTL_FILE.DatePatern='.'yyyy-MM-dd
log4j.appender.UTL_FILE.File=/your/log/dir/util.txt
log4j.appender.UTL_FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.UTL_FILE.layout.ConversionPattern=%d %-5p %m%n

log4j.appender.SYS_FILE=org.apache.log4j.DailyRollingFileAppender
log4j.appender.SYS_FILE.DatePatern='.'yyyy-MM-dd
log4j.appender.SYS_FILE.File=/your/log/dir/system.txt
log4j.appender.SYS_FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.SYS_FILE.layout.ConversionPattern=%d %-5p %m%n


HTH


----- Original Message -----
From: "Christopher Randall" <[EMAIL PROTECTED]>
To: "Log4j-User (E-mail)" <[EMAIL PROTECTED]>
Sent: Wednesday, January 02, 2002 6:53 PM
Subject: Question about setup


I would appreciate if somebody could indulge me with this architectural
question I have about Log4J:

I need to setup a logging scheme with the following characteristics:

1. Each package in our Java framework should have a corresponding
logging category (i.e. com.foo.bar)
2. Each logger category will have a different FileAppender to log to a
separate file, with a filename that corresponds to its package name
(i.e. com_foo_bar.txt)

Any suggestions on what the easiest way to set this up might be? I would
like to do as little programmatic setup as possible, putting as much of
the setup into a config file.

Thanks for your time in response,
Chris

--
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]>


--
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