Spring Application Download Log Level

I want to change the log level of a running Spring boot application.

Can I change the log level at runtime? Right now I have a log configuration in the bank itself.

+6
source share
3 answers

Changing the log level while the application is running is part of the main registrar implementation.

You did not specify the login implementation you are using, so I assume that you are using the default repository provided through spring-boot-startter-logging or spring-boot-starter-web dependencies.

Comment on any registrar related configurations from application.properties for example.

#logging.path=logs #logging.level.org.springframework.web= INFO #logging.level.=INFO 

Add logback.xml to the root of your classpath with a tag. See http://logback.qos.ch/manual/jmxConfig.html

Launch the application and open JConsole and go to the MBeans tab. Select the ch.qos.logback.classic.JMxConfigurator package. By default, find the setLoggerLevel operation e.g. org.springframework.web, DEBUG

enter image description here

The change will take effect immediately. For other log libraries, see the spring download user guide http://docs.spring.io/spring-boot/docs/current/reference/html/howto-logging.html and specific information for the library, for example. for log4j http://www.sureshpw.com/2012/04/dynamic-logging-with-log4j.html

Another approach is to repeat steps without JMX and use the configuration manager

+13
source

If you want to change the logging level of an already running Spring Boot application, you can take a look at spring -cloud-config. Refer to: http://cloud.spring.io/spring-cloud-config/ :

Spring Cloud Config provides server and client support for external configuration in a distributed system. With Config Server, you have a central place to manage the external properties for applications in all environments.

You can centrally manage properties on the configuration server and create an entry for your application.properties file (check bootstrap.properties) in your current application

 spring.application.name=application name 

Using the @RefreshScope annotation in your client application, you can update the application runtime and view the updated logging level property.

+3
source

With the release of Spring Boot 1.5, if you have an actuator in your boot application, you can do this through the REST API out of the box.

Drive unit

1.5 provides an endpoint called β€œloggers” that you can GET to view the configuration, and POST to change the runtime.

Ref.

 curl -i -X POST -H 'Content-Type: application/json' -d '{"configuredLevel": "DEBUG"}' http://localhost:8080/loggers/org.springframwork 
+2
source

All Articles