如何在SLF4j或Log4J中动态更改日志级别 [英] How to dynamically change log level in SLF4j OR Log4J
问题描述
最近我遇到了一个应用程序Loglevel动态更改的情况。应用程序管理员可以从前端将其设置为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.
预先感谢您的帮助。
-Narendra
-Narendra
推荐答案
考虑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屋!