I want to change the log level of a Spring Boot application that is running.
Is it possible to change the log level at runtime? Right now I have the logger configuration in my jar itself.
In Spring, the log level configurations can be set in the application. properties file which is processed during runtime. Spring supports 5 default log levels, ERROR , WARN , INFO , DEBUG , and TRACE , with INFO being the default log level configuration.
All the supported logging systems can have the logger levels set in the Spring Environment (for example, in application. properties ) by using logging. level. <logger-name>=<level> where level is one of TRACE, DEBUG, INFO, WARN, ERROR, FATAL, or OFF.
Now we simply need to run the application and hit http://localhost:8080/log to see the log messages.
Changing the log level while the application is running is part of the underlying logger implementation.
You did not specify the logger implementation you are using so I will assume you are using the default logback provided via the spring-boot-starter-logging or spring-boot-starter-web dependencies.
Comment out any logger related configurations from application.properties e.g.
#logging.path=logs
#logging.level.org.springframework.web= INFO
#logging.level.=INFO
Add logback.xml in the root of your classpath with tag See http://logback.qos.ch/manual/jmxConfig.html
Start the application and open JConsole and go to MBeans tab. Select the package ch.qos.logback.classic.JMxConfigurator.Under default locate the setLoggerLevel operation e.g. org.springframework.web, DEBUG
The change will be effective immediately. For other logger libraries see the spring boot user guide http://docs.spring.io/spring-boot/docs/current/reference/html/howto-logging.html And library specific information e.g. for log4j http://www.sureshpw.com/2012/04/dynamic-logging-with-log4j.html
A different approach is to repeat the about steps without JMX and use configuration watcher
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With