Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-1912

CompositeConfiguration logs warning "Unable to determine URI for configuration." However, the reconfiguration is completed.

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.8.1
    • Fix Version/s: None
    • Component/s: API
    • Labels:
      None

      Description

      Hello everybody,

      I found a possible bug in class CompositeConfiguration: Unable to determine URI for configuration. However, the reconfiguration is completed.

      The solution:
      In line 154, Class CompositeConfiguration [log4j-core-2.8.1.jar] change the condition:

      if (sourceURI != null)" --> "if (sourceURI == null)
      

      Original code:

      145    @Override
      146    public Configuration reconfigure() {
      147        LOGGER.debug("Reconfiguring composite configuration");
      148        final List<AbstractConfiguration> configs = new ArrayList<>();
      149        final ConfigurationFactory factory = ConfigurationFactory.getInstance();
      150        for (final AbstractConfiguration config : configurations) {
      151            final ConfigurationSource source = config.getConfigurationSource();
      152            final URI sourceURI = source.getURI();
      153            Configuration currentConfig;
      154            if (sourceURI != null) {
      155                LOGGER.warn("Unable to determine URI for configuration {}, changes to it will be ignored",
      156                        config.getName());
      157                currentConfig = factory.getConfiguration(getLoggerContext(), config.getName(), sourceURI);
      158                if (currentConfig == null) {
      159                    LOGGER.warn("Unable to reload configuration {}, changes to it will be ignored", config.getName());
      160                    currentConfig = config;
      161                }
      162            } else {
      163                currentConfig = config;
      164            }
      165            configs.add((AbstractConfiguration) currentConfig);
      166
      167        }
      168
      169        return new CompositeConfiguration(configs);
      170    }
      

      So it makes sense, because after that it will be tried to reload the configuration again, and if it does not work, I get a warn, otherwise is ok.

      The changed code might look like this:

          @Override
          public Configuration reconfigure() {
              LOGGER.debug("Reconfiguring composite configuration");
              final List<AbstractConfiguration> configs = new ArrayList<>();
              final ConfigurationFactory factory = ConfigurationFactory.getInstance();
              for (final AbstractConfiguration config : configurations) {
                  final ConfigurationSource source = config.getConfigurationSource();
                  final URI sourceURI = source.getURI();
                  if (sourceURI == null) {
                      LOGGER.warn("Unable to determine URI for configuration {}, changes to it will be ignored", config.getName());
                      Configuration currentConfig = factory.getConfiguration(getLoggerContext(), config.getName(), sourceURI);
                      if (currentConfig == null) {
                          LOGGER.warn("Unable to reload configuration {}, changes to it will be ignored", config.getName());
                      }
                      else {
                          LOGGER.info("Able to reload configuration {}, changes to it will be completed", config.getName());
                          configs.add((AbstractConfiguration) currentConfig);
                      }
                  } else {
                      configs.add(config);
                  }
      
              }
      
              return new CompositeConfiguration(configs);
          }
      

      Your feedback and questions are welcome. Thanks!
      Best regards,
      rri

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              rri Ronald Rivas
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - 1h
                1h
                Remaining:
                Remaining Estimate - 1h
                1h
                Logged:
                Time Spent - Not Specified
                Not Specified