【问题标题】:Log4j in tomcat not showing logsTomcat中的Log4j不显示日志
【发布时间】:2013-12-15 09:30:03
【问题描述】:

这是我的log4j.properties

# Root logger option
log4j.rootLogger=INFO, file, stdout

# Direct log messages to a log file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=${catalina.home}\MyLog\PmcDemo.log
log4j.appender.file.MaxFileSize=1MB
log4j.appender.file.MaxBackupIndex=1
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

# Direct log messages to stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

我使用的是 tomcat 6.0,在我的应用程序中我使用了来自 log4j 的 Logger,但我在服务器控制台或日志文件中看不到任何输出。我的应用程序使用 struts2 作为前端,Spring 框架作为中间层,hibernate 作为终端层。我没有看到我的应用程序日志记录如何在 tomcat 6 中启用它?

【问题讨论】:

  • 这是windows环境下的。

标签: java tomcat logging


【解决方案1】:

您需要将反斜杠切换为正斜杠:

${catalina.home}/MyLog/PmcDemo.log

或逃避他们

${catalina.home}\\MyLog\\PmcDemo.log

如果这没有帮助,请告诉我们您的项目结构以及 log4j.properties 文件的存储位置。

【讨论】:

  • 好吧,我的错,我也应该发布我的环境,我使用的是 Windows 7。
  • 好的,我建议您尝试更改为 / 无论如何。我也在使用 Windows 并使用单个 '\' 破坏了我的日志记录
  • 另请参阅 stackoverflow.com/questions/11268120/… 以获取有关此类问题的可能补救措施的其他建议...
【解决方案2】:

试试这个步骤,

如果运行 Tomcat 6.x:

 1. If you have not already done so, modify the <<TOMCAT_HOME>>/conf/catalina.properties file so that the shared classloader mechanism work the same as Tomcat 5.x.
 2. To do this, verify that the entry beginning with shared.loader= reads shared.loader=${catalina.base}/shared/classes,${catalina.base}/shared/lib/*.jar If running Tomcat 5.x or higher:

如果运行 Tomcat 5.x 或更高版本:

 3. If it does not already exist, create a "shared/classes" directory under <<TOMCAT_HOME>>.

 4. If it does not already exist, create a "shared/lib" directory under <<TOMCAT_HOME>>.
 5. Copy log4j-###.jar into <<TOMCAT_HOME>>/shared/lib.

    **Note:** Any specific version of log4j-###.jar should work. You can download the stable log4j version 1.2 installation from http://logging.apache.org/log4j/1.2/download.html

 6. Copy a log4j.properties file into <<TOMCAT>>/shared/classes.

示例
要让名为“initiate.log”的日志文件显示在 &lt;&lt;TOMCAT_HOME&gt;&gt;/logs 目录中,log4j.properties 文件的初始版本是:

    log4j.rootLogger=ERROR, R

    log4j.appender.stdout=org.apache.log4j.ConsoleAppender
    log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

    # Pattern to output the caller's file name and line number.
    log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n

    log4j.appender.R=org.apache.log4j.RollingFileAppender
    log4j.appender.R.File=${catalina.home}/logs/initiate.log

    log4j.appender.R.MaxFileSize=1000KB
    log4j.appender.R.MaxBackupIndex=5

    log4j.appender.R.layout=org.apache.log4j.PatternLayout
    log4j.appender.R.layout.ConversionPattern=%d{ABSOLUTE} 5-5p %c{2} - %m %n

    log4j.logger.org.springframework=ERROR
    log4j.logger.org.springframework.web.servlet.mvc=ERROR

    #set to DEBUG to see hibernate and connection-pool logging output
    log4j.logger.org.hibernate=ERROR
    log4j.logger.org.apache.commons.dbcp=ERROR

    #set to DEBUG to see Initiate-specific logging output
    log4j.logger.com.initiatesystems=DEBUG

    #set to DEBUG to set Initiate-specific verbose logging output
    log4j.logger.verbose=ERROR

引用自:http://pic.dhe.ibm.com/infocenter/initiate/v9r5/index.jsp?topic=%2Fcom.ibm.datatrust.doc%2Ftopics%2Ft_datatrust_configuring_log4j_logging_apachetomcat.html

【讨论】:

  • 这不是修复,而是解决方法。通常最好为每个应用程序使用单独的 log4j.properties,然后使用一个全局的。
猜你喜欢
  • 2018-12-07
  • 1970-01-01
  • 2020-09-21
  • 1970-01-01
  • 2023-03-25
  • 1970-01-01
  • 1970-01-01
  • 2018-03-24
  • 1970-01-01
相关资源
最近更新 更多