How to change log level on a Java slf4j logger in a kubernetes managed service in runtime?

5/11/2017

I have a spring boot java service running in a google kubernetes managed container engine. The Java service logs via the slf4j api (and logs are forwarded to google stackdriver, but that's not in scope of this question).

I can change the logging level by changing the kubernetes deployment file:

spec:
  template:
    spec:
      containers:
        env:
        - name: JAVA_OPTS
          value: -Xmx1g -Dlogging.level.com.example=DEBUG

This works, but it requires me to redeploy the service (restart the container by applying an updated deloyment yaml file) in order to change log level. If I compare with working with a "regular" tomcat server running a regular war-file, it can put a file-watch to a logback.xml-file and changes in this file takes effect on the logging without having to restart the tomcat. Is there a similar way to control log levels in runtime in kubernetes managed spring boot services?

-- Andreas Lundgren
google-cloud-platform
java
kubernetes
slf4j
spring-boot

2 Answers

10/25/2017

If you use Spring Boot Admin, from Codecentric (https://github.com/codecentric/spring-boot-admin) you could modify log levels at runtime via JMX/Jolokia.

You could also implement a "Spring Cloud Bus" which could push out your config changes and refresh the application contexts after you commit your changes to your configuration management system (git).

http://cloud.spring.io/spring-cloud-static/springcloud.html#_push_notifications_and_spring_cloud_bus

-- DaShaun
Source: StackOverflow

5/11/2017

Have you tried using the logger endpoint? introduced in spring-boot 1.5

I guess this would be ok if you have 1 instance but if there's multiple maybe this is a bad approach.

-- Pär Nilsson
Source: StackOverflow