开发者

Logger.setLevel() doesn't enable logging correctly

Situat开发者_运维知识库ion: I have this log4j logger:

private static final Logger logger = Logger.getLogger(ThisClassName.class);

And am trying to set it programatically through:

Logger.getLogger(ThisClassName.class).setLevel(Level.DEBUG);

Still, DEBUG level prints are swalloed (while INFO prints are printed successfully).

Even this bit has no effect: Logger.getRootLogger().setLevel(Level.DEBUG);

Calling logger.debug("foo") reaches Category.forcedLog() and ConsoleAppender.doAppend(), and then fails (quits) at:

if(!isAsSevereAsThreshold(event.getLevel()))

Any idea why this is happening?


Your appender is configured with a threshold greater than debug, so while the logger doesn't ignore the entries, your appender doesn't record it. You need to configure the threshold of your ConsoleAppender to be DEBUG as well, either through your config file or programatically:

((ConsoleAppender)someLogger.getAppender("CONSOLE")).setThreshold(Level.DEBUG);

Config files are usually the more elegant solution for this sort of thing.

Edit: Note that apparently, any subclass of AppenderSkeleton (including ConsoleAppender) shouldn't have a threshold filter set by default. So it's likely that somewhere in your configuration you're actually manually assigning a threshold ( > Debug) to that appender, as @justkt hints.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜