使用log4j2.xml进行tomcat 7内部日志记录 [英] tomcat 7 internal logging with log4j2.xml

查看:601
本文介绍了使用log4j2.xml进行tomcat 7内部日志记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用log4j2配置tomcat 7内部日志记录.我已遵循在Tomcat 6中使用log4j2记录服务器类的答案.

I am trying to configure tomcat 7 internal logging with log4j2. I have followed the answer provided at Logging server classes in Tomcat 6 with log4j2.

我正在使用tomcat 7.0.54和log4j-core-2.1.jarlog4j-api-2.1.jar. 我已经下载了额外功能,并执行了以下所有步骤,但是当我启动tomcat时,出现了错误:

I am using tomcat 7.0.54, and log4j-core-2.1.jar, log4j-api-2.1.jar. I have down loaded the extras and did all the steps below, but when I start tomcat, I get an error:

ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.

这些是我执行的步骤:

  • log4j2.xml放入$CATALINA_BASE/lib
  • 从扩展"中下载tomcat-juli.jartomcat-juli-adapters.jar
  • log4j-api-2.1.jarlog4j-core-2.1.jarlog4j-jul-2.1.jartomcat-juli-adapters.jar从附加"放入$CATALINA_HOME/lib.
  • 用"extras"中的tomcat-juli.jar替换$CATALINA_HOME/bin/tomcat-juli.jar.
  • 删除$CATALINA_BASE/conf/logging.properties
  • 将日志记录管理器设置为使用log4j2-jul网桥(log4j-jul-2.1.jar)中的管理器.更改catalina.sh以确保类路径包括bin/tomcat-juli.jarlib/log4j-jul-2.1.jarlib/log4j-api-2.1.jarlib/log4j-core-2.1.jar,并且用于启动tomcat的命令包括 -Djava.util.logging.manager = org.apache.logging.log4j.jul.LogManager`
  • put log4j2.xml in $CATALINA_BASE/lib
  • download tomcat-juli.jar and tomcat-juli-adapters.jar from "extras"
  • put log4j-api-2.1.jar, log4j-core-2.1.jar, log4j-jul-2.1.jar, and tomcat-juli-adapters.jar from "extras" into $CATALINA_HOME/lib.
  • replace $CATALINA_HOME/bin/tomcat-juli.jar with tomcat-juli.jar from "extras".
  • delete $CATALINA_BASE/conf/logging.properties
  • set the logging manager to use the manager from the log4j2-jul bridge (log4j-jul-2.1.jar). Alter catalina.sh to ensure that the classpath includes bin/tomcat-juli.jar, lib/log4j-jul-2.1.jar, lib/log4j-api-2.1.jar and lib/log4j-core-2.1.jar, and the command used to start tomcat includes -Djava.util.logging.manager=org.apache.logging.log4j.jul.LogManager`

我什至尝试在catalina.sh中添加此(LOGGING_CONFIG="-Djava.util.logging.config.file=$CATALINA_HOME/lib/log4j2.xml"),但是没有用.

I even tried adding this (LOGGING_CONFIG="-Djava.util.logging.config.file=$CATALINA_HOME/lib/log4j2.xml") in catalina.sh but didn't work.

请让我知道是否有人可以成功配置它.

Please let me know if anyone could configure it successfully.

推荐答案

我采取了以下步骤,并且对我有用.

I took the following steps and it worked for me.

  1. 将以下罐子放在$ CATALINA_HOME/lib中
    • log4j 2核心(log4j-core-2.4.1.jar)
    • log4j 2 API(log4j-api-2.4.1.jar)
    • log4 j 1.0的log4j 2桥(log4j-1.2-api-2.4.1.jar)
    • tomcat extras中的
    • tomcat-juli-adapters.jar
  1. Put the following jars in $CATALINA_HOME/lib
    • log4j 2 core (log4j-core-2.4.1.jar)
    • log4j 2 api (log4j-api-2.4.1.jar)
    • log4j 2 bridge for log4 j 1.0 (log4j-1.2-api-2.4.1.jar)
    • tomcat-juli-adapters.jar from tomcat extras

诀窍是遵循官方 tomcat 7文档进行设置log4J 1.X,但改为使用log4j2工件.此外,此解决方案不需要$ CATALINA_HOME/bin/catalina.sh或任何其他文件$ CATALINA_HOME/bin

The trick is to follow the official tomcat 7 documentation to setup log4J 1.X but instead use log4j2 artifacts instead. Also this solution does not require any changes in $CATALINA_HOME/bin/catalina.sh or any other files $CATALINA_HOME/bin

这篇关于使用log4j2.xml进行tomcat 7内部日志记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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