In view of debugging Logback and log4j file cutting has been unsuccessful, with the use of shell script to cut the log files under Tomcat (if you have in the Logback or log4j use file cutting success, you can leave the use of the way, first thank you)
1: Cut the crap and put the script directly:
#!/bin/sh
log_dir=/var/log/tomcat
monitor_file=$1 The absolute path to the #tomcat目录下的catalina. Out file
file_size= ' du $ Monitor_file | awk ' {print '} '
if [$file _size-ge 102400]
then
if [!-D $log _dir]
then
mkdir/var/log/tomcat #创 Build save cut file directory, this path can be modified by itself, save to the directory you want
fi
cp $1/var/log/tomcat/log-' date +%y-%m-%d-%h%m%s '. Log #保存日志文件
echo ' Date +%y-%m-%d-%h:%m:%s ': File Cut ">>/var/log/tomcat/split.log #记录切割日志
echo" "> #清空tomcat的log Catalina.out file Content
fi
Description: This script is very simple, Linux with a timer does not have minutes to scan the size of the log file, that is, when the file is larger than 100M, first copy the file to the specified directory, and then empty the original Tomcat log files. Here is using crontab to use the timer, as for this command of the syntax here is not much to say, interested in Google, there is still a small shortfall, because it is scheduled every minute to scan the log file, so the final cut file size will still be between the 100~102m.
And then use the timer to execute the script regularly.
2: Edit the timer code with CRONTAB-E
*/1 * * * * sh/lee_js/monitor_script.sh/opt/apache-tomcat-7.0.67/logs/catalina.out #第一个路径是脚本的路径, The second parameter is the absolute path of the Catalina.out file under Tomcat
and then save
This is the log cut.
Note: If you do not have the crontab command to use the Yum installation:
Yum install Vixie-cron
yum install Crontabs
The above is a small set to introduce the shell script to cut Tomcat log files, I hope to help you, if you have any questions please give me a message, small set will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!