I believe log4j1.3 has LoggerRepository.isPristine() which will tell you
that, but that's not available in the 1.2.8 release.  The only way I could
think of doing it is doing as you suggest, and analyzing any attached
appenders, or checking for any logger in the hierachy that has a non-null
Level, which would indicate that it has been 'touched', but this is
obviously not ideal.

cheers,

Paul Smith
> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, November 16, 2004 2:21 AM
> To: [EMAIL PROTECTED]
> 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 [EMAIL PROTECTED]
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to