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 retrieve all appenders (stdout and altstdout)?
log4j.rootLogger=error, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.altstdout=org.apache.log4j.ConsoleAppender
log4j.appender.altstdout.layout=org.apache.log4j.PatternLayout
# Pattern to output the caller's file name and line number.
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n
log4j.appender.altstdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n
Enumeration appenders = logger. getAllAppenders(); . . . fileBackupIndex = rollingFileAppender. getMaxBackupIndex();
The Log4j logging settings are stored in the file app_data /conf/server/log4j. properties, where app_data is the application data folder. You can edit this file directly on the server or open it by clicking Settings > Logging. Note: Do not change the name and location of the server log.
If you want access to all appenders configured for all loggers you must do something like this
for (Enumeration loggers=LogManager.getCurrentLoggers(); loggers.hasMoreElements(); ) {
Logger logger = (Logger) loggers.nextElement();
for (Enumeration appenders=logger.getAllAppenders(); appenders.hasMoreElements(); ) {
Appender appender = (Appender) appenders.nextElement();
...
I don't know why log4j has no method like LogManager.getAllAppenders(), but it looks like
disadvantage.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With