logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tom.Goe...@kp.org
Subject Re: Use different log files inside one program
Date Fri, 29 Oct 2004 15:24:33 GMT
The method:
PropertyConfigurator.configure

can as input either a File or a Properties object.


I have an application where I read a template properties file, modify a 
few of the values inside the Properties object, and then call 
PropertyConfigurator.configure and pass in the modifed properties. I think 
you can easily do the same.

An easy approach would be to use a System property (which can be set on 
the command line when the java app is launched) to identify the name of 
the file that you want to log to for that particular run. Then use that 
value to change the Properties object as needed.

Another approach, if you are willing to use separate configuration files 
for each different app, is to use the System property 
(log4j.configuration--I think that's correct) to identify the exact static 
configuration file that you want to use.

--
Tom Goetze

Tom.Goetze@kp.org




"Winston Huang" <weiqingh@mail.com>
10/29/2004 06:41 AM
Please respond to "Log4J Users List"

 
        To:     log4j-user@logging.apache.org
        cc: 
        Subject:        Use different log files inside one program


hi there,

i have a java program that behaves like a cron job which kicks off
jobs based on certain conditions. each job is implemented by a a
Runnable. i would like to have each job use a different log file. the
best i can do so far is to set NDC for the Runnable or print out the
thread name in the output. but all the logs still go to the same
file. it's more convenient if each job can write to a different log
file, identified by the job name for example. is there any way to do
it? 

note that each Runnable can invoke other common classes which in turn
use log4j inside. e.g. Runnable1 may call Util.foo, and Runnable2 may
call Util.foo as well. the logging output from Util.foo should go to
different log files based on the Runnable. however Util.foo uses the
static logger that's assoicated with the Util class itself. 

any help is greatly appreciated. 
Winston

-- 
___________________________________________________________
Sign-up for Ads Free at Mail.com
http://promo.mail.com/adsfreejump.htm


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




Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message