logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Vikas Jaitly <vik...@aztec.soft.net>
Subject Help needed for logging to multiple files !!!
Date Wed, 29 Sep 2004 06:05:01 GMT
Hi All,
I am trying to use log4j for my java application, and am stuck with a
problem. I have already tried a search on the archive but could not find a
solution for the current problem. Please provide me with a solution or point
me to the thread if it has already been discussed.
 
Problem statement
----------------------
I have a java application(not a *web* application), where multiple tasks can
be performed at a time .I want to log all the output to a file by name
<taskname>.log for each of the running tasks. Since the task name is not
available until runtime, I cannot configure it using the log4j.xml file.
 
One of the solutions I tried was to have a logger (as instance variable) for
each task having a name "com.mypackage.task.<taskname>. During the
initialisation I add a fileappender to the logger. Till now every thing
works perfectly, and I can see the log messages for different tasks in
different files.
 
The problem starts, if the task is stopped and started again during the same
session. For each new creation ofthe same task, the log mesage starts
getting duplicated in the same file.
 
Following are my questions :
1) Is the approach that I am following correct( having separate logger
instance for each task)? or is there a better solution ?
 
2) Is there a way to remove appender (or is it better to remove the logger
itself, once the task gets completed) I could not find a method to remove a
logger:-(
 
3) How is the performance effected if I have multiple loggers registered
(using logger.getLogger()) but do not remove it. During peak performance, I
could have hundreds of tasks running in parallel.
 
4) Does it help if I have each task running in a separate thread, so that we
have a logger setup for a thread (possibly get some info from the thread
local and initialize based on it). I am asking this because, I can foresee
my application to grow to a multithreaded application soon.
Any pointers on using such a approach ?
 
5) Can the same be achieved using some kind of filter ? 
 
Thanks in advance,
 
Regards,
Vikas
 
 

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