spring-projects / spring-boot

Spring Boot helps you to create Spring-powered, production-grade applications and services with absolute minimum fuss.
https://spring.io/projects/spring-boot
Apache License 2.0
75.1k stars 40.67k forks source link

spring property not getting populated on refreshing logback file programtically #42156

Open sourav-jha opened 1 month ago

sourav-jha commented 1 month ago

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.

mhalbritter commented 1 month ago

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!

spring-projects-issues commented 1 month ago

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 commented 1 month ago

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.

sourav-jha commented 3 weeks ago

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

mhalbritter commented 3 weeks ago

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

sourav-jha commented 2 weeks ago

log_issue.zip sample application

philwebb commented 2 weeks ago

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.