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 5 months 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