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 Preetham Kajekar <pr...@cisco.com> on 2003/05/30 13:08:04 UTC

Getting all the appenders in all the loggers

Hi,
 Is there a way I can get all the appenders for all the loggers I have
in my system.

 My goal is to roll-over the provious log files every time my program
starts up. So I would have code like in an init() function which would
get all appenders, and then call the roll-over method for all the
appeders.

Thanks,
 ~preetham


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


Re: Getting all the appenders in all the loggers

Posted by Avner BenHanoch <av...@kinor.com>.
you can always put all appenders in something like Set (see java.util.Set
and its implementation classes), then iterate on your set and get all the
elements uniquely.

----- Original Message -----
From: "Preetham Kajekar" <pr...@cisco.com>
To: "'Log4J Users List'" <lo...@jakarta.apache.org>
Sent: Friday, May 30, 2003 2:23 PM
Subject: RE: Getting all the appenders in all the loggers


>
>
> > -----Original Message-----
> > From: Vinodh Lakshminarayan [mailto:vinodhl@yahoo.com]
> > Sent: Friday, May 30, 2003 5:27 PM
> > To: Log4J Users List
> > Subject: Re: Getting all the appenders in all the loggers
> >
> >
> >
> > Try the following code
> >
> > Logger logger = .......... file://Your logger
>
>  I need to do it for all the loggers in the system. I know there is
> getAllLoggers() in LogManager. I was wondering if there is any other way
> of doing this coz with this approach, I may land up getting the same
> appender twice (if is associated with 2 loggers) and consequently
> rolling over twice. This can be avoided using a Hashtable etc, but more
> importantly, the code will be more computation than necessary.
>
> ~thanks.
>  ~preetham
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: log4j-user-help@jakarta.apache.org
>
>


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


RE: Getting all the appenders in all the loggers

Posted by Preetham Kajekar <pr...@cisco.com>.

> -----Original Message-----
> From: Vinodh Lakshminarayan [mailto:vinodhl@yahoo.com] 
> Sent: Friday, May 30, 2003 5:27 PM
> To: Log4J Users List
> Subject: Re: Getting all the appenders in all the loggers
> 
> 
> 
> Try the following code
> 
> Logger logger = .......... //Your logger

 I need to do it for all the loggers in the system. I know there is
getAllLoggers() in LogManager. I was wondering if there is any other way
of doing this coz with this approach, I may land up getting the same
appender twice (if is associated with 2 loggers) and consequently
rolling over twice. This can be avoided using a Hashtable etc, but more
importantly, the code will be more computation than necessary.

~thanks.
 ~preetham


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


Re: Getting all the appenders in all the loggers

Posted by Vinodh Lakshminarayan <vi...@yahoo.com>.
Try the following code

Logger logger = .......... //Your logger

Enumeration e = logger.getAllAppenders();
Appender app = null;
while(e.hasMoreElements())
{
     app = (Appender) e.nextElement();
     if(app instanceof RollingFileAppender)
     {

     //Do your roll over here
     }
}



Regards

Vinodh


Preetham Kajekar <pr...@cisco.com> wrote:
Hi,
Is there a way I can get all the appenders for all the loggers I have
in my system.

My goal is to roll-over the provious log files every time my program
starts up. So I would have code like in an init() function which would
get all appenders, and then call the roll-over method for all the
appeders.

Thanks,
~preetham


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


---------------------------------
Do you Yahoo!?
Free online calendar with sync to Outlook(TM).