zoukankan      html  css  js  c++  java
  • spring log4j.properties 没有日志的问题

    一.   log4j.properties

    1. log4j.properties放在spring工程的src/main/rescours目录下无法读取。

       测试后发现需要把log4j.properties文件放在src/main/webapp/WEB-INF目录下,

    2. web.xml配置

    <context-param>
        <param-name>log4jConfigLocation</param-name>
        <param-value>/WEB-INF/log4j.properties</param-value>
    </context-param>

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

    3. log4j.properties中日志文件路径

    ${webapp.root}/....  

    4. 代码

    private static final Log log= LogFactory.getLog("logname");

    二. log4j.xml

    1. log4j.xml放在spring工程的src/main/rescours目录下可以读取。

    2. web.xml配置

    <context-param>
        <param-name>log4jConfigLocation</param-name>
        <param-value>classpath:log4j.xml</param-value>
    </context-param>

    <context-param>
        <param-name>rootLevel</param-name>
        <param-value>DEBUG</param-value>
    </context-param>

    <context-param>
        <param-name>loggingLevel</param-name>
        <param-value>INFO</param-value>
    </context-param>

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

    3. log4j.properties中日志文件路径

    ${webapp.root}/....  

    4. 代码

    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;

    private static final Logger log= LoggerFactory.getLogger("logname");

  • 相关阅读:
    WebApi系列知识总结
    用Jquery选择器计算table中的某一列某一行的合计
    layui table指定某一行样式
    数据库-SqlServer 行转列,列转行
    数据库缓存之Memcache知识点
    hdu 2471 简单DP
    nyist0j 35 表达式求值
    html 实现网址链接
    nyist 220 推桌子
    nyist 500 一字棋
  • 原文地址:https://www.cnblogs.com/myibm/p/5979937.html
Copyright © 2011-2022 走看看