tengine2.3.3生成的日志以这种格式结尾2022-01-01 15:00:00.000,每个日志最大5MB,自动清理1个月以前的日志,日志包括access和error日志,给出详细配置教程
时间: 2023-02-08 14:13:02 浏览: 70
Tengine是一个高性能的Web服务器,您可以通过以下步骤来配置Tengine的日志:
1. 修改Tengine的配置文件nginx.conf,在http块里添加以下配置:
```
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /path/to/access.log main;
error_log /path/to/error.log notice;
```
这样就可以在/path/to/access.log和/path/to/error.log文件里分别记录access和error日志了
2. 添加如下配置修改日志的格式,
```
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" $msec';
access_log /path/to/access.log main;
```
3. 配置自动清理一个月前的日志,可以使用linux的cron来实现,比如:
```
59 23 28 * * root find /path/to/log -mtime +30 -name "access.log*" -exec rm -f {} \;
```
这样就可以在每月的28号的23:59分执行删除/path/to/log文件夹下一个月前access.log开头的文件了
4. 设置日志每个文件最大为5MB,可以使用linux的logrotate工具,添加配置文件如下:
```
/path/to/access.log {
size 5M
rotate 10
missingok
notifempty
compress
delaycompress
copytruncate
}
```
这样就可以在access.log文件超过5MB时,使用rotate 10进行分割,并压缩为.gz