手机版
你好,游客 登录 注册
背景:
阅读新闻

Linux下切分Tomcat的catalina.out日志文件

[日期:2011-04-05] 来源:Linux社区  作者:Linux [字体:大 中 小]

rotating catalina.out in tomcat 5.5 using cronolog
Submitted by theCamel on Tue, 08/14/2007 - 16:25.
Tags: Tomcat
Cronolog provides a solution to the age-old problem of tomcat's catalina.out log file not rotating and growing so large that the server must be stopped to deal with it.

First, install cronolog, which can be downloaded from here.

the cronolog command works like this:

cronolog [OPTIONS] logfile-spec

a simple example is:

cronolog /logs/catalina.out.%Y-%m-%d

so once output is piped to cronolog, it will create a logfile that looks like:

catalina.out.2007-08-14

and when the date changes, it creates a new file:

catalina.out.2007-08-15

so to configure, in the catalina.sh replace this string:

org.apache.catalina.startup.Bootstrap "$@" start \
>> "$CATALINA_BASE"/logs/catalina.out 2>&1 &


with this:

org.apache.catalina.startup.Bootstrap "$@" start 2>&1 \
| /usr/local/sbin/cronolog /logs/catalina.out.%Y-%m-%d >> /dev/null &


and the catalina.out will now be rotated daily and stored in the path we specified "/logs". If you wish to keep the logs in the tomcat logs dir, just specify that path in the cronolog command in catalina.sh

| cronolog "$CATALINA_BASE"/logs/catalina.out.%Y-%m-%d >> /dev/null &


I also removed this line from catalina.sh:

touch "$CATALINA_BASE"/logs/catalina.out


as it would no longer be necessary.

so now instead of one gigantic, ever-growing catalina.out, I have this:


catalina.2007-08-10.log
catalina.2007-08-11.log
catalina.2007-08-12.log
catalina.2007-08-13.log
catalina.2007-08-14.log
catalina.2007-08-15.log


and all my old log-removal scripts can work and I no longer have to stop the tomcat server just to deal with a log file...

linux
相关资讯       Tomcat 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款