You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by John Volkar <jv...@etransport.com> on 2001/02/02 20:12:36 UTC

RE: PropertyConfigurator question

Ahem, just a quick one.  

Becareful if using this code as it's not quite right.  The
.getAllAppenders() method does NOT seem to return null if there are no
appenders on the root category (like the javadocs say it should).  It seems
to return an instance of a log4j.helpers.NullEnumeration class instead.

Maybe someone should patch the javadocs please.  (Maybe this is just for the
Root category, though?  hmmm)

Regards

John Volkar



-----Original Message-----
From: Anders Kristensen [mailto:akristensen@dynamicsoft.com]
Sent: Tuesday, January 30, 2001 8:17 AM
To: LOG4J Users Mailing List
Subject: Re: PropertyConfigurator question



Andy Kriger wrote:
> [...]
> What I want is a way to check if PropertyConfigurator is able to find
> log4j.properties and if not, then and only then call
> BasicConfigurator.configure() as a backup.
> 
> Is this possible?

You can check whether at least one Category has been added to the
default hierarchy or whether an appender has been added to the root
category:

  public static boolean isLog4jConfigured() {
    Enumeration cats = Category.getCurrentCategories();
    Enumeration rootApps = Category.getRoot().getAllAppenders();
    return cats.hasMoreElements() || rootApps != null;
  }

I haven't checked it but it ought to work.

<<-SNIP->>

Re: PropertyConfigurator question

Posted by Anders Kristensen <ak...@dynamicsoft.com>.

John Volkar wrote:
> 
> Ahem, just a quick one.
> 
> Becareful if using this code as it's not quite right.  The
> .getAllAppenders() method does NOT seem to return null if there are no
> appenders on the root category (like the javadocs say it should).  It seems
> to return an instance of a log4j.helpers.NullEnumeration class instead.
> 
> Maybe someone should patch the javadocs please.  (Maybe this is just for the
> Root category, though?  hmmm)

No it's all Categories. I've removed the offending comment. Thanks.


> 
> Regards
> 
> John Volkar
> 
> -----Original Message-----
> From: Anders Kristensen [mailto:akristensen@dynamicsoft.com]
> Sent: Tuesday, January 30, 2001 8:17 AM
> To: LOG4J Users Mailing List
> Subject: Re: PropertyConfigurator question
> 
> Andy Kriger wrote:
> > [...]
> > What I want is a way to check if PropertyConfigurator is able to find
> > log4j.properties and if not, then and only then call
> > BasicConfigurator.configure() as a backup.
> >
> > Is this possible?
> 
> You can check whether at least one Category has been added to the
> default hierarchy or whether an appender has been added to the root
> category:
> 
>   public static boolean isLog4jConfigured() {
>     Enumeration cats = Category.getCurrentCategories();
>     Enumeration rootApps = Category.getRoot().getAllAppenders();
>     return cats.hasMoreElements() || rootApps != null;
>   }
> 
> I haven't checked it but it ought to work.
> 
> <<-SNIP->>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: log4j-user-help@jakarta.apache.org

--
Anders Kristensen