使用tomcat 6在Spring webapp中设置Commons Logging / Log4j的问题 [英] Problem with Commons Logging / Log4j setup in spring webapp with tomcat 6

查看:200
本文介绍了使用tomcat 6在Spring webapp中设置Commons Logging / Log4j的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在tomcat 6下部署的apring webapp中的日志设置存在问题。

I have a problem wih a logging setup in a apring webapp deployed under tomcat 6.

webapp使用commons-logging api,应该使用运行时log4j 。日志文件已创建,但仍为空 - 没有日志条目。

The webapp uses the commons-logging api, on runtime log4j should be used. The log file is created but remains empty - no log entries occur.

设置如下:

WEB-INF / web.xml:

WEB-INF/web.xml:

 <context-param>
    <param-name>log4jConfigLocation</param-name>
    <param-value>/WEB-INF/log4j.xml</param-value>
  </context-param>
  <listener>
    <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
  </listener>

WEB-INF / classes / commons-logging.properties:

WEB-INF/classes/commons-logging.properties:

org.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger

WEB-INF / log4j.xml:

WEB-INF/log4j.xml:

<log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'>

  <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
    ...
  </appender>
  <appender name="FILE" class="org.apache.log4j.RollingFileAppender">
    <param name="File" value="${catalina.home}/logs/my.log"/>
    ...
  </appender>

  <logger name="my.package">
    <level value="INFO"/>
  </logger>

  <root>
    <level value="ERROR"/>
    <appender-ref ref="CONSOLE"/>
    <appender-ref ref="FILE"/>
  </root>
</log4j:configuration>

创建了文件logs / my.log,但没有显示日志。这是tomcat控制台上的信息日志,但没有配置布局模式。

The file logs/my.log is created, but no logs appear. The are info logs on the tomcat console, but not with the layout pattern configured.

commons-logging-1.1.1.jar和log4j-1.2.14.jar包含在WEB-INF / lib中。知道这里有什么问题吗?

The commons-logging-1.1.1.jar and log4j-1.2.14.jar are included in WEB-INF/lib. Any idea what is wrong here?

推荐答案

网上有很多记录在案的实例,警告人们使用commons-logging。因此, SLF4J 正在大受欢迎。

There are numerous documented instances on the web warning people about the use of commons-logging. So much so, that SLF4J is gaining a lot of popularity.

考虑到你对使用Tomcat和Log4j不感兴趣,你应该直接在你的应用程序中使用Log4j。特别是如果您将来不可能切换日志框架。它将降低应用程序的复杂性,并消除您使用commons-logging时遇到的任何类加载器问题。

Considering that you are not interested in using Tomcat with Log4j, you should just use Log4j directly in your application. Particularly if there is no chance that you'll be switching logging frameworks in the future. It'll reduce the complexity of your application, and get rid of any class loader issues you are having with commons-logging.

这应该是一个相对容易的搜索和替换在你的文本中,commons-logging和log4j都使用类似的调用结构来记录它们。

This should be a relatively easy search and replace in your text, as commons-logging and log4j both use a similar call structure for their logging methods.

这篇关于使用tomcat 6在Spring webapp中设置Commons Logging / Log4j的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆