spring-boot icon indicating copy to clipboard operation
spring-boot copied to clipboard

spring property not getting populated on refreshing logback file programtically

Open sourav-jha opened this issue 1 year ago • 7 comments

spring.boot.version: 3.1.12 logback.version:1.4.14 Issue: We are trying to update the logback config at runtime programatically using following code:

public class DynamicLogbackConfigurator {
  // Interface to fetch the updated logback xml
  private final S3Manager configManager;
  public void refresh() throws Exception {
    byte[] xml;
    val context = (LoggerContext) LoggerFactory.getILoggerFactory();
    val configurator = new JoranConfigurator();
    try (val logbackContent = configManager.getConfigStoreFile(ManagedFile.LOGBACK_CONFIG)) {
      xml = logbackContent.readAllBytes();
    } catch (final Exception e) {
      log.error("Failed to read logback configuration from config manager.", e);
      return;
    }
    try {
      configurator.setContext(context);
      context.reset();
      configurator.doConfigure(new ByteArrayInputStream(xml));
      log.info("Logback configuration has been refreshed from config manager.");
    } catch (final Exception e) {
    
      throw e;
    }
  }

Our logback config has spring property. On doing refresh, its not reading the spring property.

sourav-jha avatar Sep 05 '24 08:09 sourav-jha

Hello,

Spring Boot 3.1.12 is no longer OSS supported. Please upgrade to an OSS supported version and see if the problem persists. If it does, please create a minimal reproducible sample.

Thanks!

mhalbritter avatar Sep 05 '24 08:09 mhalbritter

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

spring-projects-issues avatar Sep 12 '24 08:09 spring-projects-issues

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.

spring-projects-issues avatar Sep 19 '24 08:09 spring-projects-issues

Checked for spring boot: 3.3.4 logback.version:1.5.8 found same issue. Probably issue is in code we are using JoranConfigurator. Instead we should use SpringBootJoranConfigurator. but SpringBootJoranConfigurator is not a public class

sourav-jha avatar Oct 11 '24 05:10 sourav-jha

Thanks. Can you please provide a minimal sample for us to reproduce?

mhalbritter avatar Oct 11 '24 07:10 mhalbritter

log_issue.zip sample application

sourav-jha avatar Oct 14 '24 10:10 sourav-jha

I think the use of JoranConfigurator is indeed the problem, but I'm not convinced that we should make SpringBootJoranConfigurator public. Programmatically refreshing the logging system isn't something we've considered supporting.

philwebb avatar Oct 15 '24 21:10 philwebb

We discussed this today at our team meeting and decided that we'd prefer to keep SpringBootJoranConfigurator package private. Programmatically refreshing the logging system isn't something we can prioritize at the moment.

philwebb avatar Nov 14 '24 18:11 philwebb