logging-log4j-user mailing list archives

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




Yoav, Thanks for the tip. I looked at that code, and see that the main difference
seems to be testing for the appender enumeration being null, or NullEnumeration.
I'm wondering, this seems to work only if there isn't a log4j.xml/.properties on
the classpath? I found that the reason I got FILE & CONSOLE listed when iterating
over the enumeration was because there was a log4j.xml with those appenders
specified. When I deleted that, I got A1 & A2 listed, which are the appenders
specified in my log4j.properties.

So I renamed log4j.properties to ourlog4j.properties. Then when I get the
appenders enumeration from the rootLogger, only a CONSOLE appender is listed. It
appears that the act of getting the rootLogger, or the appenders, is causing
log4j to be configured with something. I'm looking to see if there might be
another log4j.xml/.properties file in the classpath, but so far no.

Dave

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




                                                                                         
                                       
                      "Shapira, Yoav"                                                    
                                       
                      <Yoav.Shapira@mp         To:      "Log4J Users List" <log4j-user@logging.apache.org>
                      
                      i.com>                   cc:                                    
                                          
                                               Subject: RE: How to determine if log4j has
been configured                        
                      11/15/2004 11:54                                                   
                                       
                      AM                                                                 
                                       
                      Please respond                                                     
                                       
                      to "Log4J Users                                                    
                                       
                      List"                                                              
                                       
                                                                                         
                                       
                                                                                         
                                       




Hi,
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
Configurator#configure.


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
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)?
>
>TIA,
>Dave
>
>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




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







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


Mime
View raw message