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: Appender configuration question
Date Wed, 23 Apr 2008 16:55:36 GMT
On Tue, 22 Apr 2008 16:27:52 -0400
  NBW <emailnbw@gmail.com> wrote:
> I have a situation where I have my application JAR file which includes a 3rd
> party library JAR. This 3rd party library jar includes a log4j.xml file
> which configures some file appenders. 

Please contact the 3rd party and castigate them for being a bad citizen. 
 Configuration is the end-user's concern, not the library writer's concern. 
 They should not be supplying their own configuration.

> My application's main class contains a
> static Logger and its main method uses BasicConfigurator.configure(). 

So, all you want to basic Console logging with the root logger set to DEBUG?

> What I
> am noticing is that my application log output and log output from the 3rd
> party JAR are logging to BOTH the console and to the files specified in the
> 3rd party JARs log4j.xml file. 

You are experiencing the additive nature of Log4j's configuration.  Every time 
configure() is called, the configuration defined either programmatically or 
via config file will be added to the existing Logger Repository configuration.

> I want everything to only log to the
> appenders my application specifies (namely the console). Can someone give me
> some advice on doing this? Thanks.

You've got a couple options....ok three options.

1.  Continue to call BasicConfigurator.configure(), but also provide 
-Dlog4j.defaultInitOverride=true on the command line at program startup.

2.  Don't call BasicConfigurator.configure() and provide either log4j config 
file in either Properties or XML format by passing the location to it on the 
command line using -Dlog4j.configuration=myconfig.conf (can't remember if this 
needs to be a basic file path or a properly formatted file: URL???).

2.  Don't call BasicConfigurator.configure() and provide your own log4j.xml 
file (for auto-configuration, you must use log4j.xml instead of 
log4j.properties or else the 3rd party's log4j.xml will be used in preference 
to log4j.properties even if the latter is first in the classpath) and make 
sure the directory in which the file exists is placed in the classpath before 
your 3rd party jar.


Jake


---------------------------------------------------------------------
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