logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Néstor Boscán <nestor.bos...@tcs.com.ve>
Subject RE: Is there a way to get all configured loggers?
Date Thu, 03 Jan 2008 21:53:49 GMT
Thanks a lot!!! 

-----Mensaje original-----
De: David Killeffer [mailto:rayden7@gmail.com] 
Enviado el: Jueves, 03 de Enero de 2008 04:11 p.m.
Para: Log4J Users List
Asunto: Re: Is there a way to get all configured loggers?

Hi Nestor -
     I had to do something similar for a servlet I was writing recently - as
part of the servlet, I declare a logger which is then used to get all the
loggers that have been configured, and then show which appenders are
attached to which loggers.  The main function which I used to get all the
configured loggers and their appenders is like this:

    private void showLoggers(Logger mainLogger, PrintWriter out) {
        // get all the loggers
        Enumeration allLoggers = mainLogger.getLoggerRepository
        while (allLoggers.hasMoreElements()){
            Logger logger = (Logger)allLoggers.nextElement();
            // only show loggers that have appenders attached to them
            try {
                if ( logger.getAllAppenders().hasMoreElements() ) {
                    printLoggingSummary(logger, out);
            } catch (Exception e) {
                System.out.println("in showLoggerst().... " +
e.getStackTrace() + "\nMessage: " + e.getMessage() );

Hopefully this helps steer you in the right direction.

~ David

On Dec 31, 2007 3:25 PM, Néstor Boscán <nestor.boscan@tcs.com.ve> wrote:

> Hi
> Is there a way to get a list of all configured loggers?
> Regards,
> Néstor Boscán

Best Regards,
David Killeffer

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

View raw message