【重要】设置日志文件数量和文件大小限制后,日志内容较多时无法获取到最新的日志问题
记录日志时的方法checkLogSize(检查日志文件大小并自动生成备份文件)中生成备份文件时,备份文件以时间戳为前缀【如1659063483-20220729_api.log】。如果设置了文件数量限制,glob($this->config['path'] . '*.log')会按照文件名排序返回,就会导致时间戳前缀文件永远是最先删除的文件,只保留每天最后生成的日志文件,导致日志文件不完整了。
checkLogSize(Check log file size and automatically generate backup files) When backup files are generated, the backup files are prefixed with time stamps, for example, 1659063483-20220729_api.log. If the number of files limit is set, glob($this-> config['path']. '*.log') is returned by file name. As a result, the timestamp prefix file is always the first file to be deleted, and only the last log file generated each day is retained.
可以关闭数量限制,然后通过 crontab 定时执行命令来清除。
# 清除两天前的日志
$ find /home/wwwlogs/web/ -name "*.log" -mtime +2 -exec rm -f {} \;
删除最旧的文件比较合理