5

I have a Spring boot application which use logback.xml for logging configurations.I am looking for options to dynamically change log level. For instance if I have deployed an app with loglevel as ERROR,Let say I want to change this to INFO but I don't want to redeploy/restart my JVM.

Is there any possibility we can configure logback.xml like config server to achieve this

3 Answers 3

3

You can configure Logback to Automatically reloading configuration file upon modification

Sign up to request clarification or add additional context in comments.

Comments

3

Yes, this is quite possible. Expose a rest endpoint where you supply the className and log level. With slf4j you can get the LoggerContext and change the level.

    LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
    context.getLogger(className).setLevel(Level.valueOf(level));

Apache Commons logging and others have similar features.

1 Comment

plus If you need to set the log level globally for all classes [for root], you can by context.getLogger(Logger.ROOT_LOGGER_NAME).setLevel(Level.valueOf(level));
3

If you are using spring cloud then you can have this in your yml file

logging:
  level:
    root: INFO

Then you can change it and refresh the configuration using actuator refresh to fetch new configuration changes no need to restart the service.

Also if you need some sort of UI to do this stuff you can explore the Spring-cloud-dashboard It is pretty cool and uses the features from the actuator to do and show you a lot of stuff not only changing log levels.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.