简体   繁体   中英

Is it possible to change the log level of a package in log4j?

Currently I have a library that is logging certain information as ERROR. If I change my log4j settings like this:

log4j.logger.com.company.theirpackage.foo=OFF

that will completely disable the library's logging altogether. However, what I'd really like is to still see the information, but have it logged at a WARN or INFO level. In other words, when that particular code calls log.error() , I want it to be as if they had called log.warn() or log.info() instead.

Is there a way to do this with log4j?

Not directly, but you could write a custom appender that intercepts the calls, checks the levels, and then prints them at whatever level you want. Or, you could do some aspect oriented programming and intercept/change their calls.

But why would you want to change the level they log it at?

我认为这可以通过实现一个Filter来实现,其中LoggingEvent中的级别在匹配某些条件时会发生变化。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM