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 Fergus Gallagher <Fe...@OrbisUK.com> on 2002/09/06 10:36:28 UTC

Getting list of all appenders (not attached to root)

I have a config file like:

log4j.rootCategory=INFO, A1

log4j.appender.A1=.....
log4j.appender.A2=.....
log4j.appender.A3=.....


i.e., I have multiple Appenders not attached to the root category.  How can
I (programmatically) get a list of all these appenders?  I can only see how
to get at those already attached to the root via
Category.getRoot().getAllAppenders()

Fergus



-- 
Fergus Gallagher          Tel: +44 (20) 8742 1600
Orbis                     Fax: +44 (20) 8742 2649
414 Chiswick High Street  email: Fergus.Gallagher@orbisuk.com
London  W4 5TL            Web: http://www.orbisuk.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Getting list of all appenders (not attached to root)

Posted by Fergus Gallagher <Fe...@OrbisUK.com>.
Forget it, it's easy to have

	log4j.rootCategory=INFO, ${log4j.appenders}

with my configuration class providing a default value for this.

Fergus

On Fri, Sep 06, 2002 at 10:20:31AM +0100, Fergus Gallagher wrote:
> Thanks for that.  
> 
> I'll explain what I actually want to do - maybe someone can suggest a better
> way of doing it (my intended way was a bit of a hack anyway)
> 
> I have lots of apps all using the same classpath, and I would *prefer* to
> use a single log4j config file, rather than one per app, to make management
> a bit easier.
> 
> What I wanted to do was 
> 
> 	java -Dlog4j.appenders="A1,A3" ....
> 
> and have only those configured.  It would be relatively easy to add all the
> appenders to root, then remove those NOT in this list, but it would be nice
> to have the configuration fall back to something sensible if the system
> property isn't defined.
> 
> Fergus
> 
> P.S. as a related point, is the Enumeration from
> category.getAllAppenders() guaranteed to return them in the same order as
> they're defined?
> 
> 
> On Fri, Sep 06, 2002 at 10:51:16AM +0200, Ceki G?lc? wrote:
> > 
> > 
> > Appenders are instantiated only if they are attached to a logger. The
> > fact that they are mentioned in the config file has no effect.
> > 
> > As to the programmatic listing of these appenders, suffice it to say
> > that one can't list things that do not exist.
> > 
> > 
> > 
> > At 09:36 06.09.2002 +0100, you wrote:
> > >I have a config file like:
> > >
> > >log4j.rootCategory=INFO, A1
> > >
> > >log4j.appender.A1=.....
> > >log4j.appender.A2=.....
> > >log4j.appender.A3=.....
> > >
> > >
> > >i.e., I have multiple Appenders not attached to the root category.  How can
> > >I (programmatically) get a list of all these appenders?  I can only see how
> > >to get at those already attached to the root via
> > >Category.getRoot().getAllAppenders()
> > >
> > >Fergus
> > >
> 
> -- 
> Fergus Gallagher          Tel: +44 (20) 8742 1600
> Orbis                     Fax: +44 (20) 8742 2649
> 414 Chiswick High Street  email: Fergus.Gallagher@orbisuk.com
> London  W4 5TL            Web: http://www.orbisuk.com
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>

-- 
Fergus Gallagher          Tel: +44 (20) 8742 1600
Orbis                     Fax: +44 (20) 8742 2649
414 Chiswick High Street  email: Fergus.Gallagher@orbisuk.com
London  W4 5TL            Web: http://www.orbisuk.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Getting list of all appenders (not attached to root)

Posted by Fergus Gallagher <Fe...@OrbisUK.com>.
Thanks for that.  

I'll explain what I actually want to do - maybe someone can suggest a better
way of doing it (my intended way was a bit of a hack anyway)

I have lots of apps all using the same classpath, and I would *prefer* to
use a single log4j config file, rather than one per app, to make management
a bit easier.

What I wanted to do was 

	java -Dlog4j.appenders="A1,A3" ....

and have only those configured.  It would be relatively easy to add all the
appenders to root, then remove those NOT in this list, but it would be nice
to have the configuration fall back to something sensible if the system
property isn't defined.

Fergus

P.S. as a related point, is the Enumeration from
category.getAllAppenders() guaranteed to return them in the same order as
they're defined?


On Fri, Sep 06, 2002 at 10:51:16AM +0200, Ceki G?lc? wrote:
> 
> 
> Appenders are instantiated only if they are attached to a logger. The
> fact that they are mentioned in the config file has no effect.
> 
> As to the programmatic listing of these appenders, suffice it to say
> that one can't list things that do not exist.
> 
> 
> 
> At 09:36 06.09.2002 +0100, you wrote:
> >I have a config file like:
> >
> >log4j.rootCategory=INFO, A1
> >
> >log4j.appender.A1=.....
> >log4j.appender.A2=.....
> >log4j.appender.A3=.....
> >
> >
> >i.e., I have multiple Appenders not attached to the root category.  How can
> >I (programmatically) get a list of all these appenders?  I can only see how
> >to get at those already attached to the root via
> >Category.getRoot().getAllAppenders()
> >
> >Fergus
> >

-- 
Fergus Gallagher          Tel: +44 (20) 8742 1600
Orbis                     Fax: +44 (20) 8742 2649
414 Chiswick High Street  email: Fergus.Gallagher@orbisuk.com
London  W4 5TL            Web: http://www.orbisuk.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Getting list of all appenders (not attached to root)

Posted by Ceki Gülcü <ce...@qos.ch>.

Appenders are instantiated only if they are attached to a logger. The
fact that they are mentioned in the config file has no effect.

As to the programmatic listing of these appenders, suffice it to say
that one can't list things that do not exist.



At 09:36 06.09.2002 +0100, you wrote:
>I have a config file like:
>
>log4j.rootCategory=INFO, A1
>
>log4j.appender.A1=.....
>log4j.appender.A2=.....
>log4j.appender.A3=.....
>
>
>i.e., I have multiple Appenders not attached to the root category.  How can
>I (programmatically) get a list of all these appenders?  I can only see how
>to get at those already attached to the root via
>Category.getRoot().getAllAppenders()
>
>Fergus
>
>
>
>--
>Fergus Gallagher          Tel: +44 (20) 8742 1600
>Orbis                     Fax: +44 (20) 8742 2649
>414 Chiswick High Street  email: Fergus.Gallagher@orbisuk.com
>London  W4 5TL            Web: http://www.orbisuk.com
>
>--
>To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
>For additional commands, e-mail: <ma...@jakarta.apache.org>

--
Ceki

TCP implementations will follow a general principle of robustness: be
conservative in what you do, be liberal in what you accept from
others. -- Jon Postel, RFC 793



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>