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

Add an ability to load an alternative Log4j config file

    XMLWordPrintableJSON

Details

    Description

      Current Situation:
      In case of web applications, the Log4J2 loads a config file specified by the servlet context init param log4jConfiguration. If the location is classpath: location then that config file would be searched somewhere in the classpath. Usually, to keep the web application WAR self sufficient the config file is bundled in WEB-INF/classes dir of the WAR itself.

      Problem:
      The config file usually has machine/env dependent information like the log file location, the log levels etc. These values and sometimes the whole file may be different depending upon where the app is running (e.g., developer machine, qa or production etc). In many organizations, the deployment scripts/tools specify these files per env or alter the values per env during deployment time. This is very difficult to do if the config file is bundled inside the WAR. An alternative is to NOT bundle the config file inside WAR and put it in some system classpath location but that solution makes the WAR not self contained.

      Wish:
      Wish there was an ability to specify a preferred log4j config file that will be used if it exists and a fallback config file location if the preferred config file doesn't exist.

      For example, with the following in web.xml

         <context-param>
            <param-name>log4jConfiguration</param-name>
            <param-value>file:///file1.xml,classpath:file2.xml</param-value>
         </context-param>
      

      The file1.xml can be somewhere on file system or external classpath location and could be env specific. The file2.xml can be the default file bundled in the WAR itself. If file1.xml exists then it will take the precedence, if it doesn't exist then file2.xml will be used. This idea is similar to the way Spring Framework allows specifying multiple values to the location attribute when specifying property placeholder.

      Attachments

        Activity

          People

            Unassigned Unassigned
            dpandya Dushyant Pandya
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: