[英]How to stop application logs from logging into catalina.out in Tomcat
The application is running in tomcat
and has it own logger using org.apache.commons.logging.Log and org.apache.commons.logging.LogFactory.
该应用程序在
tomcat
中运行,并使用org.apache.commons.logging.Log and org.apache.commons.logging.LogFactory.
The logs are getting logged at location specified in log4j.properties
file, the location is as follows.日志记录在
log4j.properties
文件中指定的位置,位置如下。
log4j.appender.logger.File=${catalina.base}/logs/applicationlogs.log
The logs are simultaneously added in following file.日志同时添加到以下文件中。
/opt/apache-tomcat-8.0.26/logs/catalina.out /opt/apache-tomcat-8.0.26/logs/catalina.out
How to stop the application logs from getting logged in catalina.out ?如何阻止应用程序日志登录 catalina.out ?
You can try to do this:你可以尝试这样做:
"$CATALINA_BASE"/bin/catalina.sh
file"$CATALINA_BASE"/bin/catalina.sh
文件CATALINA_OUT="$CATALINA_BASE"/logs/catalina.out
CATALINA_OUT="$CATALINA_BASE"/logs/catalina.out
Don't forget to restart tomcat.不要忘记重启tomcat。
And as suggested in comments, to block writing to catalina.out
entirely, set CATALINA_OUT=/dev/null
in catalina.sh
.正如评论中所建议的,要完全阻止写入
catalina.out
,请在catalina.sh
设置CATALINA_OUT=/dev/null
。
You will see log file created as per your log configuration.您将看到根据您的日志配置创建的日志文件。
I'm using tomcat 7.0.50 and I've done following configuration.我正在使用 tomcat 7.0.50 并且我已经完成了以下配置。 To stop the application to log into catalina.out, you can do it by removing the handler.
要停止应用程序登录 catalina.out,您可以通过删除处理程序来实现。 This can be achieved by editting
conf/logging.properties
and changing:这可以通过编辑
conf/logging.properties
并更改:
.handlers = 1catalina.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler
to到
.handlers = 1catalina.org.apache.juli.FileHandler
Hope this helps.希望这可以帮助。 Let me know if I'm missing something.
如果我遗漏了什么,请告诉我。
I believe the recommended way to "augment" catalina.sh (catalina.bat on Windows) is to:我相信“增强”catalina.sh(Windows上的catalina.bat)的推荐方法是:
Just changing只是改变
CATALINA_OUT="$CATALINA_BASE"/logs/catalina.out
To到
CATALINA_OUT= /dev/null
In catalina.sh
is not enough because the CATALINA_OUT
variable will be used later in the script and that will cause an error to be thrown (aborting the startup).在
catalina.sh
中是不够的,因为稍后将在脚本中使用CATALINA_OUT
变量,这将导致抛出错误(中止启动)。
What I've done instead was, I went to the command lines themselves and edited them so that the output itself will be redirected to /dev/null
我所做的是,我自己去命令行并编辑它们,以便输出本身将被重定向到
/dev/null
(In Tomcat 9 it's in the if
block in line ~447) (在 Tomcat 9 中,它位于 ~447 行的
if
块中)
$_NOHUP "\"$_RUNJAVA\"" "\"$LOGGING_CONFIG\"" $LOGGING_MANAGER $JAVA_OPTS $CATALINA_OPTS \
-D$ENDORSED_PROP="\"$JAVA_ENDORSED_DIRS\"" \
-classpath "\"$CLASSPATH\"" \
-Djava.security.manager \
-Djava.security.policy=="\"$CATALINA_BASE/conf/catalina.policy\"" \
-Dcatalina.base="\"$CATALINA_BASE\"" \
-Dcatalina.home="\"$CATALINA_HOME\"" \
-Djava.io.tmpdir="\"$CATALINA_TMPDIR\"" \
org.apache.catalina.startup.Bootstrap "$@" start \
>> "$CATALINA_OUT" 2>&1 "&"
I've set the stdout stream to /dev/null
我已将标准输出流设置为
/dev/null
$_NOHUP "\"$_RUNJAVA\"" "\"$LOGGING_CONFIG\"" $LOGGING_MANAGER $JAVA_OPTS $CATALINA_OPTS \
-D$ENDORSED_PROP="\"$JAVA_ENDORSED_DIRS\"" \
-classpath "\"$CLASSPATH\"" \
-Djava.security.manager \
-Djava.security.policy=="\"$CATALINA_BASE/conf/catalina.policy\"" \
-Dcatalina.base="\"$CATALINA_BASE\"" \
-Dcatalina.home="\"$CATALINA_HOME\"" \
-Djava.io.tmpdir="\"$CATALINA_TMPDIR\"" \
org.apache.catalina.startup.Bootstrap "$@" start \
>> /dev/null 2>&1 "&"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.