【问题标题】:Custom log4j.properties location for Spring web applicationSpring Web 应用程序的自定义 log4j.properties 位置
【发布时间】:2015-11-11 05:07:30
【问题描述】:

是否可以为 log4j 1.x 的 log4j.properties 文件提供自定义位置? 我不想将该文件包含在项目的资源文件夹中。

【问题讨论】:

    标签: spring logging configuration configuration-files


    【解决方案1】:

    使用上下文参数log4jConfigLocation 配置web.xml 中的org.springframework.web.util.Log4jConfigListener。

    <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:

    用于 Web 环境中自定义 log4j 初始化的引导侦听器。代表Log4jWebConfigurer...


    Log4jWebConfigurer JavaDoc:

    log4j 配置文件的位置;要么是“类路径:”位置 (例如“classpath:myLog4j.properties”),绝对文件 URL(例如 "file:C:/log4j.properties),或相对于网络的普通路径 应用程序根目录(例如“/WEB-INF/log4j.properties”)。如果不 指定,默认 log4j 初始化将应用(“log4j.properties” 或类路径中的“log4j.xml”;请参阅 log4j 文档 细节)。 “log4jRefreshInterval”:

    【讨论】:

    • 谢谢拉尔夫。如果我想以编程方式配置文件位置,是否应该注入自定义 Log4jWebConfigurer 实现?
    猜你喜欢
    • 2012-04-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-12
    相关资源
    最近更新 更多