如何在 SLF4j 或 Log4J 中动态更改日志级别 [英] How to dynamically change log level in SLF4j OR Log4J

查看:82
本文介绍了如何在 SLF4j 或 Log4J 中动态更改日志级别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我遇到了应用程序日志级别动态变化的情况.应用程序管理员可以从前端将其设置为 INFO/DEBUG/WARN.根据所选的日志级别,必须更改应用程序日志记录.

Recently I encountered a situtation where Application Loglevel changes dynamically. Application Admin can set it to INFO/DEBUG/ WARN from front end. Based on the log level choosen be him application logging must be changed.

我确信记录器支持这种情况,但不知道我怎样才能做到这一点.如果你们对此有任何想法/想法,请告诉我.

I am sure loggers support this scenario, but not sure how can I achive this. If any of you have idea/thoughts on this please let me know.

预先感谢您的帮助.

-纳伦德拉

推荐答案

考虑 Logback http://logback.qos.ch/ - 流行的 log4j 项目的继承者,从 log4j 离开的地方开始".如果指示这样做,logback-classic 将扫描其配置文件中的更改,并在配置文件更改时自动重新配置自己.此外,您可以使用 JMX 控制 Logback 的日志级别.

Consider Logback http://logback.qos.ch/ - "a successor to the popular log4j project, picking up where log4j leaves off". If instructed to do so, logback-classic will scan for changes in its configuration file and automatically reconfigure itself when the configuration file changes. Besides, you can control Logback's logging levels with JMX.

这篇关于如何在 SLF4j 或 Log4J 中动态更改日志级别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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