logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bender Heri" <HBen...@Ergonomics.ch>
Subject RE: Use different log files inside one program
Date Wed, 22 Feb 2006 17:29:12 GMT
If you use static thread names (I thought first of thread ID's which are runtime dependent)
you can of course define everything in config file. But you have to define an appender and
the whole logger collection for each thread name. Said "logger collection": I assume you dont
want to loose the main log4j feature to finetune the log levels for different packages and

Within my approach you have only one appender and one logger collection in config file. The
appender config can define a root file name which you can fetch in code to change it to whatever
you need, i.e. use the informations stored in MDC.

Getting the correct logger in code you have to consider following:
- Unless a class is used in different context's (I mean to have different log file) you can
make the logger as a static class member.
- If a given instance of a class is used only in one context you can use a logger member which
is initialized at instantiating time of the class
- If you have singleton classes (factories etc.) or class instances whose methods are executed
in different contexts you must get the logger within each method as local variable.

Creating everything is not a good option because you loose the other main feature of log4j
(finetuning of the logging can be done without recompiling).


> -----Original Message-----
> From: James Stauffer [mailto:stauffer.james@gmail.com]
> Sent: Wednesday, February 22, 2006 4:55 PM
> To: Log4J Users List
> Subject: Re: Use different log files inside one program
> Given what you said it appears that either the config file or the code
> needs to give a filename for each thread.  If you can do it in code
> then you may be able to do it in the config file.  The config file
> would of course only work if the thread names were basically static.
> Another option is to create the thread trunks as specified and attach
> the appenders in code (as would have to be done with the repository
> selector).  Is there any advantage to using a repository selector over
> this idea?  The only advantage that comes to mind is that the
> repository selector makes it easier to get the logger.  For my example
> you would probably have to get the logger inside each method instead
> of making it a class member.

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

View raw message