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

廉价感情. 提交于 2019-12-10 16:14:52

问题


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?


回答1:


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?




回答2:


I think this is possible, by implementing a Filter, in which the level inside a LoggingEvent is changed when it matches certain conditions.



来源:https://stackoverflow.com/questions/2060362/is-it-possible-to-change-the-log-level-of-a-package-in-log4j

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!