Spring日志正在写入,而Normal日志不使用log4j写入

时间:2014-07-21 10:51:34

标签: java xml spring logging

我正在使用Log4j.xml来记录我的系统,我有两个项目,一个是spring项目,另一个是普通的java项目,

我为两个项目都配置了log4j.xml,pblm是,只有弹簧注入的日志被写入日志文件,并且正常的java日志没有写入日志文件,你能帮我一下究竟是什么pblm ,我在哪里做错了?

的log4j.xml `

    <appender name="scoringenine.trace" class="org.apache.log4j.DailyRollingFileAppender">
        <param name="File" value="/logs/scoringengine/Trace.log" />
        <param name="Append" value="true" />
        <layout class="org.apache.log4j.PatternLayout">
        <param name="ConversionPattern" value="%d | %5p %X{SessionID} %t %n %l : %m  %n%n%n" /> 
        </layout>
        </appender>  
    <appender name="util.trace" class="org.apache.log4j.DailyRollingFileAppender">
        <param name="File" value="/logs/util/Util.log" />
        <param name="Append" value="true" />
        <layout class="org.apache.log4j.PatternLayout">
        <param name="ConversionPattern" value="%d | %5p %X{SessionID} %t %n %l : %m  %n%n%n" /> 
        </layout>
        </appender>
<category name="com.core" additivity="true">
        <priority value="info" />
        <appender-ref ref="scoringenine.trace"/>
    </category> 
<category name="com.util" additivity="true">
        <priority value="info" />
        <appender-ref ref="util.trace"/>
    </category> 

`

的web.xml `

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
    /WEB-INF/config/spring/applicationcontext.xml
    </param-value>
  </context-param>
  <context-param>
    <param-name>log4jConfigLocation</param-name>
    <param-value>classpath:log4j.xml</param-value>
  </context-param>
  <context-param>
    <param-name>log4jExposeWebAppRoot</param-name>
    <param-value>false</param-value>
  </context-param>
    <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
    <listener>
    <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
  </listener>

spring.xml

<bean id="mqLogger" class="org.apache.log4j.Logger" factory-method="getLogger">
        <constructor-arg value="com.*.mq"></constructor-arg>
    </bean>

`

  

我的java

`

import org.apache.log4j.Logger;
    Class Utils{
    private static Logger logger = Logger.getLogger(Utils.class.getName());
    logger.log("inside utils");
    }

`

  

我的classpath中有log4j,slflog4j,commons-lang.jar   这个looger不打印(Util.log)util.trace,appender没有登录日志文件,其中spring注入日志(Trace.log)scorengine.trace appender正在记录...

1 个答案:

答案 0 :(得分:0)

LogFactory是一个Apache Commons Logging工厂,因为它有一个不同的框架。您需要像这样设置记录器:

private static final Logger LOG = Logger.getLogger(Utils.class);

确保您已定义此导入:

import org.apache.log4j.Logger;