如何在log4j.xml中设置CATALINA_HOME?[英] How to set CATALINA_HOME in log4j.xml?

本文是小编为大家收集整理的关于如何在log4j.xml中设置CATALINA_HOME?的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我需要这样的东西:

" param name =" file" value =" $ {catalina_home}/logs/log4j.log"

我看到了很多类似的问题,但是没有工作解决方案.

推荐答案

您可以执行以下操作:

  1. 使用-D选项将CATALINA_HOME作为环境变量发送.您只需要运行

set JAVA_OPTS=%JAVA_OPTS% -DCATALINA_HOME=%CATALINA_HOME%如果您在Windows上或 export JAVA_OPTS=${JAVA_OPTS} -DCATALINA_HOME=$CATALINA_HOME对于unix.

现在只使用$ {catalina_home}到您的log4j配置文件中,这应该有效.

其他推荐答案

用于tomcat 6.0或较新的使用catalina.base(而不是catalina.home):

param name="File" value="${catalina.base}/logs/log4j.log"

根据主机系统,两个可能不同,例如:

catalina.home: /usr/share/tomcat7
catalina.base: /var/lib/tomcat7 

catalina.home有bin文件夹.

在catalina.base下有logs,logs,webapps和其他文件夹/链接.

tomcat使用catalina.base本身来配置记录目录 - 请参见conf/logging.properties在哪里说:

1catalina.org.apache.juli.FileHandler.directory = ${catalina.base}/logs

其他推荐答案

param name="File" value="${catalina.home}/logs/log4j.log"

catalina.home属性已经由tomcat提供.

tomcat 5.5登录页面上,找到一个(非常)简短的示例以及以下问题中的其他细节:

log4j相对路径

本文地址:https://www.itbaoku.cn/post/1574880.html

问题描述

I need something like this:

"param name="File" value="${CATALINA_HOME}/logs/log4j.log"

I saw a lot of similar questions, but there is no working solutions.

推荐答案

You can do the following:

  1. send the CATALINA_HOME as an environment variable using -D option. You just have to run

set JAVA_OPTS=%JAVA_OPTS% -DCATALINA_HOME=%CATALINA_HOME% if you are on windows or export JAVA_OPTS=${JAVA_OPTS} -DCATALINA_HOME=$CATALINA_HOME for unix.

Now just use ${CATALINA_HOME} into your log4j configuration file and this should work.

其他推荐答案

For Tomcat 6.0 or newer use catalina.base (rather than catalina.home):

param name="File" value="${catalina.base}/logs/log4j.log"

Depending on the host system, the two may be different, for example:

catalina.home: /usr/share/tomcat7
catalina.base: /var/lib/tomcat7 

Under catalina.home there's the bin folder.

Under catalina.base there are conf, logs, webapps and other folders/links.

Tomcat uses catalina.base itself to configure the logging directory - see conf/logging.properties where it says:

1catalina.org.apache.juli.FileHandler.directory = ${catalina.base}/logs

其他推荐答案

param name="File" value="${catalina.home}/logs/log4j.log"

The catalina.home property is already made available by Tomcat.

Find a (very) brief example on the Tomcat 5.5 logging page and additional detail in the following SO question:

Log4j, configuring a Web App to use a relative path