2

Is it possible to provide custom location for the log4j.properties file for the log4j 1.x? I don't want to include the file in the project's resources folder.

superM
  • 8,605
  • 8
  • 42
  • 51

1 Answers1

1

configure the org.springframework.web.util.Log4jConfigListener in your web.xml with context-parameter log4jConfigLocation.

<context-param>
    <param-name>log4jConfigLocation</param-name>
    <param-value>file:C:/log4j.properties</param-value>
</context-param>

<listener>
    <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>

Log4jConfigListener JavaDoc:

Bootstrap listener for custom log4j initialization in a web environment. Delegates to Log4jWebConfigurer...


Log4jWebConfigurer JavaDoc:

Location of the log4j config file; either a "classpath:" location (e.g. "classpath:myLog4j.properties"), an absolute file URL (e.g. "file:C:/log4j.properties), or a plain path relative to the web application root directory (e.g. "/WEB-INF/log4j.properties"). If not specified, default log4j initialization will apply ("log4j.properties" or "log4j.xml" in the class path; see the log4j documentation for details). "log4jRefreshInterval":

Community
  • 1
  • 1
Ralph
  • 118,862
  • 56
  • 287
  • 383
  • Thanks Ralph. If I want to configure the file location programmatically, should I inject a custom Log4jWebConfigurer implementation? – superM Aug 19 '15 at 08:22