在tomcat配置的项目中有时会在tomcat/logs文件夹中自动生成好多log文件,如:host-manager.2008-01-02.log,localhost.2008-01-02.log,manager.2008-01-02.log,catalina.2008-01-02.log,admin.2008-01-07.log,如果不需要生成这些文件,可以配置tomcat/conf文件夹中的logging.properties文件,把下面的内容段给注释掉,以后重新启动tomcat就不会再生成以上的日志文件了。
#1catalina.org.apache.juli.FileHandler.level = FINE
#1catalina.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
#1catalina.org.apache.juli.FileHandler.prefix = catalina.
#2localhost.org.apache.juli.FileHandler.level = FINE
#2localhost.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
#2localhost.org.apache.juli.FileHandler.prefix = localhost.
#3manager.org.apache.juli.FileHandler.level = FINE
#3manager.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
#3manager.org.apache.juli.FileHandler.prefix = manager.
#4admin.org.apache.juli.FileHandler.level = FINE
#4admin.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
#4admin.org.apache.juli.FileHandler.prefix = admin.
#5host-manager.org.apache.juli.FileHandler.level = FINE
#5host-manager.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
#5host-manager.org.apache.juli.FileHandler.prefix = host-manager.
这样logs下面还是只产生catalina.out 但是catalina.out会一直堆积在一个文件中,使用以下方法可以进行按日切割:
下载LINUX下的小软件cronolog https://yunpan.cn/cuiDcCiFFTBnh 访问密码 e1ab 建议使用root权限进行按装
解压缩
# tar zxvf cronolog-1.6.2.tar.gz
进入cronolog安装文件所在目录
# cd cronolog-1.6.2
运行安装
# ./configure
# make
# make install
成功后 运行which cronolog会找到对应的路径 /usr/local/sbin/cronolog
在tomcat的bin目录的catalina.sh中找到:
182行左右
if [ -z "$CATALINA_OUT" ] ; then
CATALINA_OUT="$CATALINA_BASE"/logs/catalina.out
修改为
if [ -z "$CATALINA_OUT" ] ; then
CATALINA_OUT="$CATALINA_BASE"/logs/catalina.%Y-%m-%d.out
------------------------------------------------------------------------------------------
372行左右
org.apache.catalina.startup.Bootstrap “$@” start \
>> “$CATALINA_BASE”/logs/catalina.out 2>&1 &
修改为
org.apache.catalina.startup.Bootstrap "$@" start 2>&1 \
| /usr/local/sbin/cronolog "$CATALINA_OUT"/logs/catalina.%Y-%m-%d.out >> /dev/null &
上面会有一行touch “$CATALINA_BASE”/logs/catalina.out
把其注释掉即可
这样每天就会产生一个catalina.2xxx-0x-xx.out的文件 零点自动分割