Search code examples
javalogginglog4jslf4j

How to dynamically change log level in SLF4j OR Log4J


Recently I encountered a situation 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. How can I achieve this?


Solution

  • 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.