[prev in list] [next in list] [prev in thread] [next in thread] 

List:       log4j-user
Subject:    AW: [SPAM (Bayesain Analysis)] - Log file per thread - Bayesian Filter detected spam
From:       "Bender Heri" <HBender () Ergonomics ! ch>
Date:       2009-05-04 9:46:26
Message-ID: 3FE38194C8A3334A959B64B7D9A1E27B83940C () plejaden ! seychelles ! ergo
[Download RAW message or body]

Log4j distinguishes between Loggers and Appenders for a good reason:
  - Loggers define WHAT is logged (level, source)
  - Appenders define WHERE the log statement goes (console, file, etc.) and how it is \
formatted You want to have a new file for each new thread, so this is an appender \
issue which you cannot solve by creating a new appender.  Of course you can create a \
Logger as you suggested, but then you have to pass this logger instance along your \
callstack (or make it globally accessible in the current thread context). If you do \
so you will loose most of the benefits which log4j offers. You implement then \
something like your own logging framework, a thing which to avoid was the main goal \
of inventing log4j. Follow the suggestion of Jake Kjome to search after this \
discussions in this mailing list and implement your RepositorySelector, based on MDC. \
There were even examples posted. Heri


-----Ursprüngliche Nachricht-----
Von: Kaspar Fischer [mailto:fischerk@inf.ethz.ch] 
Gesendet: Samstag, 2. Mai 2009 16:54
An: log4j-user@logging.apache.org
Betreff: [SPAM (Bayesain Analysis)] - Log file per thread - Bayesian Filter detected \
spam

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



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


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic