简体   繁体   English

如何阻止应用程序日志登录到 Tomcat 中的 catalina.out

[英]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:你可以尝试这样做:

  1. Edit "$CATALINA_BASE"/bin/catalina.sh file编辑"$CATALINA_BASE"/bin/catalina.sh文件
  2. Find CATALINA_OUT="$CATALINA_BASE"/logs/catalina.out找到CATALINA_OUT="$CATALINA_BASE"/logs/catalina.out
  3. Replace with new path.替换为新路径。

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

If your application is using a console appender, then those logs will go to catalina.out.如果您的应用程序使用控制台附加程序,那么这些日志将转到 catalina.out。 You might want to check that in your application.您可能想在您的应用程序中检查它。 To disable logging to catalina.out, you can check discussion: here要禁用到 catalina.out 的日志记录,您可以查看讨论: 这里

  1. Find CATALINA_OUT="$CATALINA_BASE"/logs/catalina.out in catalina.sh $CATALINA_BASE/bin在 catalina.sh $CATALINA_BASE/bin 中找到 CATALINA_OUT="$CATALINA_BASE"/logs/catalina.out
  2. Set CATALINA_OUT=/dev/null设置 CATALINA_OUT=/dev/null
  3. Restart Tomcat重启Tomcat

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)的推荐方法是:

  1. Create or update a script in ${CATALINA_BASE}/bin called setenv.sh (setenv.bat)在 ${CATALINA_BASE}/bin 中创建或更新名为setenv.sh (setenv.bat) 的脚本
  2. Add a line to set: CATALINA_OUT=/dev/null as noted above.添加一行设置: CATALINA_OUT=/dev/null如上所述。
  3. This script will be executed before executing catalina.sh/bat which will use any vars set.该脚本将在执行 catalina.sh/bat 之前执行,它将使用任何变量集。 This is also the correct way to add to the CLASSPATH, add JAVA_OPTS, etc. without messing with catalina.sh/bat directly, which may be updated (overriden) with each tomcat upgrade.这也是添加到 CLASSPATH、添加 JAVA_OPTS 等的正确方法,而不会直接搞乱 catalina.sh/bat,它可能会随着每次 tomcat 升级而更新(覆盖)。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM