[logback-user] How to retrieve parent logger?

Christian Migowski chrismfwrd at gmail.com
Thu Nov 24 14:37:43 CET 2011


how can I get the parent logger of a given logger in logback?
What I want is to retrieve a list of all effective appenders on a
given logger, I suppose therefore I need to call
iteratorForAppenders() on the logger itself as well as on all parents,
log4j had logger.getParent() but I cannot find something similar in logback.

thanks in advance,
best regards,

P.S. what I really want is to port this from log4j to logback, it gets
a list of all logfiles attached to a given logger:

        org.apache.log4j.Logger testlogger =
        ArrayList<String> recvdMsg = new ArrayList<String>();
        while (testlogger != null && testlogger instanceof
org.apache.log4j.Logger) {
            Enumeration<Appender> loggers = testlogger.getAllAppenders();
            while (loggers.hasMoreElements()) {
                Appender x = loggers.nextElement();
                if (x instanceof FileAppender) {
                    String filename = ((FileAppender) x).getFile();
                    if (filename != null) {
                        File logfile = new File(filename);
                        try {
                        } catch (IOException e) {
                            //so we don't add the path, thats enough handling
            testlogger = (org.apache.log4j.Logger) testlogger.getParent();

More information about the Logback-user mailing list