是否可以在log4j中更改软件包的日志级别? [英] Is it possible to change the log level of a package in log4j?

查看:55
本文介绍了是否可以在log4j中更改软件包的日志级别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前,我有一个库,该库将某些信息记录为ERROR.如果我这样更改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

将完全禁用该库的日志记录.但是,我真正想要的是仍然查看信息,但是将其记录在WARN或INFO级别.换句话说,当该特定代码调用log.error()时,我希望它看起来像是调用了log.warn()log.info()一样.

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.

有没有办法用log4j做到这一点?

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?

这篇关于是否可以在log4j中更改软件包的日志级别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆