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

ConfigurationFactory cannot find config file property normalized by EnvironmentPropertySource

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.14.1
    • 2.18.0
    • Configuration
    • None

    Description

      I am setting `LOG4J_CONFIGURATION_FILE` as an environment variable, and also have a `log4j2.component.properties` file that specifies a different value for `log4j2.configurationFile`.

      When `PropertyUtils$Environment.reload` handles each key value pair and normalizes the key, `EnvironmentPropertySource.getNormalForm` normalizes the environment variable to `LOG4J_CONFIGURATION_FILE` but `PropertiesPropertySource.getNormalForm`  normalizes the property from the file as `log4j2.configurationFile`. So both values end up in the `normalized` Map.

      Then when `ConfigurationFactory` gets the configuration file property it only looks for `log4j.configurationFile` and ignores the LOG4J_CONFIGURATION_FILE environment variable.

      This seems to contradict the documentation which says that environment variables should take precedence over properties files.

      If I'm not mistaken and this is truly a bug, then I'd be happy to work on a PR if it would get it resolved more quickly. I would just need some guidance about the proper solution. Should `EnvironmentPropertySource.getNormalForm` be updated to produce the same style output as `PropertyPropertySource.getNormalForm`? The tests indicate that the current behavior is not an accident, so I'm unsure what ought to be done.

      Attachments

        Issue Links

          Activity

            People

              pkarwasz Piotr Karwasz
              Burke David
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: