2

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
  • 12,043
  • 3
  • 22
  • 44
  • 1
    Please check this will help you [dynamically change log level in SLF4J.](http://stackoverflow.com/questions/13442967/how-to-dynamically-change-log-level-in-slf4j-or-log4j) – Nallamachu May 11 '17 at 10:52

2 Answers2

0

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
  • 2,259
  • 15
  • 19
0

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
  • 3,722
  • 2
  • 27
  • 29