简体   繁体   English

如何停止Tomcat日志记录?

[英]How to stop Tomcat logging?

Tomcat automatically does its logging, and the logging files are all under /logs directory. Tomcat 会自动进行日志记录,日志文件都在/logs目录下。 As far as I know, the logging property is /conf/logging.properties .据我所知,日志属性是/conf/logging.properties How can I stop all the logging?如何停止所有日志记录?

To stop access log (default tomcat setting) go to:要停止访问日志(默认的 tomcat 设置),请转到:

conf/server.xml

and remove the following config:并删除以下配置:

    <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
           prefix="localhost_access_log." suffix=".txt"
           pattern="%h %l %u %t &quot;%r&quot; %s %b" />

to disable common log, go to:要禁用公共日志,请转到:

conf/logging.properties

and comment the following line并评论以下行

handlers = 1catalina.org.apache.juli.FileHandler, .....

Don't start Tomcat.不要启动Tomcat。 No Tomcat, no logging.没有Tomcat,没有日志记录。

On a more serious note, don't.更严重的是,不要。 Just don't.只是不要。 This sounds like a surefire recipe to cause problems when you're gone, not available or don't remember anymore what you did.这听起来像是一个万无一失的方法,会在您离开、不可用或不再记得您做了什么时引起问题。

Instead, install a log rotator which deletes old log files after N days.相反,安装一个日志轮换器,它会在 N 天后删除旧的日志文件。

Also make sure that Tomcat doesn't write too much into catalina.out since you can't rotate that.还要确保 Tomcat 不会在catalina.out写入太多内容,因为您无法旋转它。

For this, I patch the start script and pipe through head -10000 .为此,我修补了启动脚本并通过head -10000管道。 Replace this替换这个

>> "$CATALINA_OUT" 2>&1 "&"

with

2>&1 | head -10000 >> "$CATALINA_OUT" &

If there is an error starting Tomcat, I'll still see it.如果启动Tomcat时出现错误,我仍然会看到它。 But no more than 10'000 lines of log will be written to that file, so it won't grow forever.但不会超过 10'000 行日志写入该文件,因此它不会永远增长。

Note: Simply deleting catalina.out will not work.注意:简单地删除catalina.out行不通的。 On Windows, it will fail since it's still open.在 Windows 上,它会失败,因为它仍然是打开的。 On Unix, only the directory entry will be deleted (making the file inaccessible for anyone except processed which have it open).在 Unix 上,只有目录条目会被删除(使文件无法被任何人访问,除非打开它的已处理文件)。 The file will still take up space on the hard disk and it will continue to grow.该文件仍会占用硬盘空间,并且会继续增长。

Related articles:相关文章:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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