概述
对uwsgi日志进行切割
过程
1. 配置uwsgi,增加以下内容
1 2 |
logto=/var/log/uwsgi touch-logreopen=/var/log/uwsgi/.touchforlogrotat |
2. 编写SHELL脚本
1 2 3 4 5 6 7 8 |
#!/bin/bash LOGDIR="/var/log/uwsgi" DATE=`date -d "yesterday" +"%Y-%m-%d"` NEWDIR=${LOGDIR}/${DATE} #新建文件夹history用来放旧日志 mkdir -p ${NEWDIR} mv ${LOGDIR}/uwsgi.log ${NEWDIR}/uwsgi-${DATE}.log #将旧日志重新以日期命名 touch ${LOGDIR}/uwsgi.log touch ${LOGDIR}/.touchforlogrotat |
3. 制作定时计划
1 2 3 4 5 6 7 8 9 |
''' * * * * * 执行任务 第一个* 一小时当中的第几分钟:0-59 第二个* 一天当中的第几个小时:0-23 第三个* 一月当中的第几天:1-31 第四个* 一年当中的第几个月:1-12 第五个* 一周当中的第几个星期:0-7 0,7都代表周日 ''' 0 0 * * * sh /shell/uwsgi_log_cut.sh #代表每天0点执行脚本 uwsgi_log_cut.sh |
备注
问题1:
使用借鉴资料中的脚本时,出现日志文件被移动之后,无法在日志目录自动创建日志文件。
解决方式:
通过脚本创建日志文件,需要在更新touchforlogrotat之前执行。