Search code examples
spring-bootlogback

Spring Boot application log level


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.


Solution

  • 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

    enter image description here

    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