On May 5, 2009, at 5:17 PM, Martin Fernau wrote:
Hello,
I've a problem adding a Filter at runtime.
My log4j.properties looks like this:
--- cut
log4j.rootLogger=info, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
--- cut
During runtime I want to add a new FileAppender for certain paths
like this:
--- cut
FileAppender fileAppender = new FileAppender(
new PatternLayout("%d [%t] %-5p %c %x - %m%n"),
fileName, true);
fileAppender.setName("file");
Logger logger = Logger.getLogger("some.package");
logger.addAppender(fileAppender);
--- cut
this works very well.
Now I want to chage the output of my logger during runtime to also
print DEBUG
messages.
I tried this code but failed so far:
--- cut
Logger logger = Logger.getLogger("some.package");
FileAppender appender = (FileAppender)logger.getAppender("file");
LevelMatchFilter lmf = new LevelMatchFilter();
lmf.setLevelToMatch("DEBUG");
lmf.setAcceptOnMatch(true);
appender.addFilter(lmf);
// Test settings
logger.debug("TEST");
--- cut
But this don't work. The test-Message isn't printed to the
FileLogger. Only
info, error and fatal messages are printed. How can I change the
Logging
meachnics during runtime that debuging messages are printed?
Regards,
Martin
A filter would only come into play once the event got to the
appender. Your configuration has specified that all logging requests
lower than info are discarded which occurs prior to the event being
packaged into a LoggingEvent and dispatched to the appenders.
The more straight-forward mechanism would be to modify the threshold
on the root logger programmatically. No need to use a Filter for this
case.
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
For additional commands, e-mail: log4j-user-h...@logging.apache.org