logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Shapira, Yoav" <Yoav.Shap...@mpi.com>
Subject RE: How to determine if log4j has been configured
Date Mon, 15 Nov 2004 16:54:58 GMT

This wiki page has code to determine whether log4j has been configured
or not: http://wiki.apache.org/logging-log4j/UsefulCode.  It is good
practice to use this or similar code instead of always calling

Your detection code is somewhat close (more in spirit) of the above
code, but its implementation is lacking a bit.

One further point: for detecting whether log4j has been configured, it's
good to inspect the root logger and its appenders.  However, note that
app servers or other libraries may attach appenders not to the root
logger, but to their own package root.  For example, Tomcat attaches its
appenders in org.apache.catalina and below.  You can follow the same
practice and achieve better isolation of your appenders from other
programs' within the same JVM.

Yoav Shapira http://www.yoavshapira.com

>-----Original Message-----
>From: Dave.Derry@Equifax.com [mailto:Dave.Derry@Equifax.com]
>Sent: Monday, November 15, 2004 10:21 AM
>To: log4j-user@logging.apache.org
>Subject: How to determine if log4j has been configured
>I have a number of applications that all derive from a common base
>also share a log4j.properties file. Because having multiple
>in seperate VMs) writing to the same log file is disasterous, I
>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
>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
>when trying to log a message . The error is "ERROR: invalid console
>config detected, console stream is looping". I would like to detect if
>log4j has
>been configured (by JBoss) before I configure the PropertyConfigurator
>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
>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
>testing for a known named appender specified in the JBoss log4j
>file (which I really have no control over)?
>We must begin not just to act, but to think, for there is no better
>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
>disclosure, copying, distribution or use of this information and note
>actions are prohibited.  If you have received this transmission in
>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

This e-mail, including any attachments, is a confidential business communication, and may
contain information that is confidential, proprietary and/or privileged.  This e-mail is intended
only for the individual(s) to whom it is addressed, and may not be saved, copied, printed,
disclosed or used by anyone else.  If you are not the(an) intended recipient, please immediately
delete this e-mail from your computer system and notify the sender.  Thank you.

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

View raw message