logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kaspar Fischer <fisch...@inf.ethz.ch>
Subject Log file per thread
Date Sat, 02 May 2009 14:53:45 GMT
Dear list,

I am looking for a way to create a log file per thread (actually, per  
Quartz job that gets run).

I've googled quite a bit and found a few approaches, in particular  
KeyFileAppender [1]. All I have seen seem to rely on the MDC and  
KeyFileAppender seems to have a resource leak [2].

I am wondering whether there is a simply way to programmatically  
create, at the beginning of my thread, a logger with a given name and  
closing it at the end of the thread. Has anybody accomplished  
something like this?

   public void run()
   {
      String id = ...; // thread name or whatever
      Logger logger = ...; // Create a logger with a basename and the id
      try
      {
        // ...
      }
      finally
      {
        logger.close(); // Something like this is needed to make sure
                        // old logs do not keep hanging around
      }
   }

Many thanks,
Kaspar

[1] https://issues.apache.org/bugzilla/show_bug.cgi?id=19597
[2] http://www.mail-archive.com/log4j-user@logging.apache.org/msg07295.html

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


Mime
View raw message