Java Tomcat 控制台日志到文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26359894/
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
Tomcat console log to a file
提问by Hariprasath
Im using Apache Tomcat 7. When I'm running Tomcat with security manager and with the -Djava.security.debug
parameterI'm getting so much of text in console. I can't read the text in console. So I need the console log into some file. How can I achieve this?
我使用Apache Tomcat 7。当我使用安全管理器和-Djava.security.debug
参数运行 Tomcat 时,我在控制台中收到了大量文本。我无法阅读控制台中的文本。所以我需要控制台登录到某个文件。我怎样才能做到这一点?
回答by Ankur Singhal
Using catalina.bat
run can start the tomcat in the current console instead of a new console , so you can redirect all the standard error and standard output stream of this command to a file using
使用catalina.bat
run 可以在当前控制台而不是新控制台中启动 tomcat,因此您可以使用该命令将此命令的所有标准错误和标准输出流重定向到一个文件
catalina.bat run > tomcat.log
回答by Ankur Singhal
Remove ConsoleHandler
from logging configuration. In conf/logging.properties
:
ConsoleHandler
从日志记录配置中删除。在conf/logging.properties
:
Change this -
改变这个——
.handlers = 1catalina.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler
To this -
对此——
.handlers = 1catalina.org.apache.juli.FileHandler
The logs will be in the file catalina.log
.
日志将在文件中catalina.log
。
If you want to disable console logging for selected applications, you can set swallowOutput
in true in the <Context>
element.
如果要为选定的应用程序禁用控制台日志记录,可以swallowOutput
在<Context>
元素中设置为 true 。
...
<Context path="..." swallowOutput="true">
...
回答by alok
for ubuntu user, use following command:
对于 ubuntu 用户,使用以下命令:
- cd /opt/apache-tomcat-8.0.36/bin$
- ./catalina.sh run > tomcat.log
- cd /opt/apache-tomcat-8.0.36/bin$
- ./catalina.sh 运行 > tomcat.log
you will get the logs. Once you run this command you will get all the log files under /opt/apache-tomcat-8.0.36/logs folder..
你会得到日志。运行此命令后,您将获得 /opt/apache-tomcat-8.0.36/logs 文件夹下的所有日志文件。