logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dave.De...@Equifax.com
Subject How to determine if log4j has been configured
Date Mon, 15 Nov 2004 15:20:54 GMT

I have a number of applications that all derive from a common base class. They
also share a log4j.properties file. Because having multiple applications (running
in seperate VMs) writing to the same log file is disasterous, I configure log4j
in the ctor by calling the property configurator:

                  props.load( this
.getClass().getClassLoader().getResourceAsStream( "log4j.properties" ) );
                  PropertyConfigurator.configure( props );

I then enumerate the appenders, and modify any FileAppenders to specify a
sub-class specific log file.

This is working fine for applications that run stand-alone. However a couple of
these applications run as services under JBoss. In these cases I get an error
when trying to log a message . The error is "ERROR: invalid console appender
config detected, console stream is looping". I would like to detect if log4j has
been configured (by JBoss) before I configure the PropertyConfigurator (and skip
that if JBoss has already configured log4j).

I tried this code prior to calling the PropertyConfigurator:
//          Logger rootLogger = Logger.getRootLogger();
//          if( rootLogger == null )
//                System.out.println( "Root Logger not yet set!!" );
//          else
//          {
//                System.out.println( "Root logger already set!" );
//                Enumeration appenders = rootLogger.getAllAppenders();
//                while( appenders.hasMoreElements() )
//                {
//                      System.out.println(
((Appender)appenders.nextElement()).getName() );
//                }
//          }

But it said that there were 2 appenders (named FILE and CONSOLE). I'm guessing
that getting the root logger (or else the appenders) caused log4j to load a
default configuration. So, is there a way I can tell if log4j is configured, and
if that configuration is other than the default configuration? Other than by
testing for a known named appender specified in the JBoss log4j configuration
file (which I really have no control over)?


We must begin not just to act, but to think, for there is no better slave
than the one who believes his slavery to be freedom, and we are in
no greater peril than when we cannot see the chains on our minds
because there are yet no chains on our feet.
-- Michael Reid

This message contains information from Equifax Inc. which may be confidential and
privileged.  If you are not an intended recipient, please refrain from any
disclosure, copying, distribution or use of this information and note that such
actions are prohibited.  If you have received this transmission in error, please
notify by e-mail postmaster@equifax.com.

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

View raw message