java 如何阻止应用程序日志登录到 Tomcat 中的 catalina.out
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34648592/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to stop application logs from logging into catalina.out in Tomcat
提问by rajb
The application is running in tomcat
and has it own logger using 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.
应用程序正在运行tomcat
并使用它自己的记录器org.apache.commons.logging.Log and org.apache.commons.logging.LogFactory.
日志记录在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 ?
回答by m.aibin
You can try to do this:
你可以尝试这样做:
- Edit
"$CATALINA_BASE"/bin/catalina.sh
file - Find
CATALINA_OUT="$CATALINA_BASE"/logs/catalina.out
- Replace with new path.
- 编辑
"$CATALINA_BASE"/bin/catalina.sh
文件 - 寻找
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_OUT=/dev/null
在catalina.sh
.
回答by VivekJ
回答by jprism
- Find CATALINA_OUT="$CATALINA_BASE"/logs/catalina.out in catalina.sh $CATALINA_BASE/bin
- Set CATALINA_OUT=/dev/null
- Restart Tomcat
- 在 catalina.sh $CATALINA_BASE/bin 中找到 CATALINA_OUT="$CATALINA_BASE"/logs/catalina.out
- 设置 CATALINA_OUT=/dev/null
- 重启Tomcat
You will see log file created as per your log configuration.
您将看到根据您的日志配置创建的日志文件。
回答by Nikunj
I'm using tomcat 7.0.50 and I've done following configuration.
To stop the application to log into catalina.out, you can do it by removing the handler.
This can be achieved by editting conf/logging.properties
and changing:
我正在使用 tomcat 7.0.50 并且我已经完成了以下配置。要停止应用程序登录 catalina.out,您可以通过删除处理程序来实现。这可以通过编辑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.
希望这可以帮助。如果我遗漏了什么,请告诉我。
回答by PST
I believe the recommended way to "augment" catalina.sh (catalina.bat on Windows) is to:
我相信“增强” catalina.sh(Windows 上的 catalina.bat)的推荐方法是:
- Create or update a script in ${CATALINA_BASE}/bin called setenv.sh(setenv.bat)
- Add a line to set: CATALINA_OUT=/dev/nullas noted above.
- This script will be executed before executing catalina.sh/bat which will use any vars set. 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.
- 在 ${CATALINA_BASE}/bin 中创建或更新名为setenv.sh(setenv.bat)的脚本
- 添加一行设置:CATALINA_OUT=/dev/null如上所述。
- 该脚本将在执行 catalina.sh/bat 之前执行,它将使用任何变量集。这也是添加到CLASSPATH、添加JAVA_OPTS等的正确方法,无需直接搞乱catalina.sh/bat,每次tomcat升级时可能会更新(覆盖)。