Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 399
Prabhakar D Avatar asked Aug 25 '15 04:08

Prabhakar D


People also ask

What is log level in Spring Boot?

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.

How do I set logging levels in application properties?

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.

Where are Spring Boot application logs?

Now we simply need to run the application and hit http://localhost:8080/log to see the log messages.


1 Answers

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

  • Logback Automatically reloading configuration file upon modification
  • Log4j configureAndWatch(java.lang.String, long)
like image 91
Haim Raman Avatar answered Sep 27 '22 21:09

Haim Raman