logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jacob Kjome <h...@visi.com>
Subject Re: Problem with Log4j (Configuration)
Date Sat, 18 Dec 2004 17:31:45 GMT
At 05:20 PM 12/18/2004 +0100, you wrote:
 >
 >Amir,
 >
 >Are A.txt and B.txt the configuration files or the files where logging
 >output goes?
 >

I'm pretty sure he means that the .txt files are his log files and since he 
has two separate configurations, he expects appA's output to go to one file 
(as it was configured in his appA config file) and he expects appB's output 
to go to separate file (as it is configured in his appB config file).  The 
problem is that there is only one config [file] per logger 
repository.  When he says "appA" and "appB", he means two jar files in the 
same application.

The answer to this is that the approach is flawed.  The way I interpret 
this is that ApplicationA.jar and ApplicationB.jar both have a log4j config 
file in their roots.  This is a bad practice as someone else may use, for 
instance, ApplicationA.jar in their app but not want to have 
ApplicationA.jar defining their logger configuration.  The problem is 
thinking that configuration is happening per/library.  It actually happens 
per logger repository which, by default, is essentially per visible 
classloader hierarchy.  If a repository selector is used, the configuration 
happens per whatever criteria the selector uses as a demarcation of logger 
repositories.  This can add complexity which is necessary at times, but 
probably not here.

Because of this, one should not distribute config files in jars.  Logging 
is for the end user, not the creator of the library.  Remove the config 
files from the libraries and use a single config file per/application.  At 
this point, it is easy to send the output of the two libraries (with 
distinct package names) to separate log files...

<appender name="File1" class="org.apache.log4j.FileAppender">
     <param name="File" value="file1.log" />
</appender>
<appender name="File2" class="org.apache.log4j.FileAppender">
     <param name="File" value="file2.log" />
</appender>

<logger name="com.mycompany.librarya" additivity="false">
     <level value="debug"/>
     <appender-ref ref="File1"/>
</logger>

<logger name="com.mycompany.libraryb" additivity="false">
     <level value="debug"/>
     <appender-ref ref="File2"/>
</logger>

<root>
    <level value="warn"/>
    <appender-ref ref="Console"/>
</root>


I hope that answers the question.

Jake

 >At 06:13 AM 12/17/2004, Ran//-\\mir wrote:
 >
 >>Apologies are mine if this issue is discussed already.
 >>I have two different applications i-e two separate jar files
 >>(ApplicationA.jar and ApplicationB.jar).
 >>Both use log4j for logging to separate files (A.txt and B.txt).
 >>Now the scenario is
 >>ApplicationB uses ApplicationA jar file. I have placed ApplicationA.jar
 >>and log4j.jar in WEB_INF/lib folder of ApplicationB. When ApplicationB
 >>runs, I expect to get logs in different files but unfortunately this does
 >>not happen. ApplicationA makes some logging in B.txt and ApplicationB in
 >>A.txt. Though both are using different configuration files.
 >>Is this normal? What is the solution to the problem?
 >>Thanking in advance.
 >>Amir
 >
 >--
 >Ceki Gülcü
 >
 >   The complete log4j manual: http://qos.ch/log4j/
 >
 >
 >
 >---------------------------------------------------------------------
 >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


Mime
View raw message