Just a point of clarification - the part of the code in the try block:
if ( logger.getAllAppenders().hasMoreElements() ) {
printLoggingSummary(logger, out);
}
was used because if you don't ensure that you're only looking at the loggers
that have appenders attached, you might get a list of a whole bunch of
loggers you don't care about (that was happening to me) - this way you're
only going to be calling the printLoggingSummary() function on loggers that
have appenders on them (presumably those are the ones you're interested in).
On Jan 3, 2008 3:41 PM, David Killeffer <[EMAIL PROTECTED]> wrote:
> 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().getRootLogger().getLoggerRepository().getCurrentLoggers();
>
> 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 < [EMAIL PROTECTED]> wrote:
>
> > Hi
> >
> > Is there a way to get a list of all configured loggers?
> >
> > Regards,
> >
> > Néstor Boscán
> >
>
>
>
> --
> Best Regards,
> David Killeffer
--
Best Regards,
David Killeffer