Is it possible to retrieve a list of all appenders configured in log4j at run time?
I\'ll flesh out the scenario a little more. Given the following config how would
I want to add something that took me a while to understand.
If you look at the figure below (which I copied from here), you can see, that even though the logger com.foo.bar
will print to the root loggers FileAppender, its appender list is still null. So you cannot get all appenders the logger will write to with the method logger.getAllAppenders()
.
For this you need to iterate through all the parents also and the root logger seperately. Because you cannot iterate logger.getParent()
to root logger (root logger returns null - see documentation of getParent()). As far as I know, you have to access the rootLoggers' appenders seperately via Logger.getRootLogger().getAllAppenders().