tengine 2.3.3 设置日志最大5MB,超过了则建立一个新的日志,日志名字以当前时间结尾,时间格式(2022-01-01 10:10:10.000)
时间: 2023-02-08 12:13:02 浏览: 75
在 Tengine 2.3.3 中,可以使用 "error_log" 指令来设置日志文件的大小。具体格式如下:
```error_log /path/to/log/file.log max=5M;```
其中 "/path/to/log/file.log" 是日志文件的路径,"max=5M" 表示文件最大为5MB,当文件超过这个大小时,会建立一个新的日志文件。
需要注意的是,此指令默认是追加日志,如需要每次重写文件 可以加上 'noreopen' 或者 'off'。
如果需要在日志文件名后面加上当前时间,可以使用 "log_format" 指令来设置,例如:
```
log_format custom '$time_local $remote_addr $remote_user $request '
'[$status $bytes_sent $request_time $upstream_response_time $pipe] $request_length $request_time $bytes_sent';
```
其中,time_local 是当前时间,格式为 "2022-01-01 10:10:10.000"
这里只是举例, 实际使用还要根据需求来设置, 你可以通过参考官网来调整这些参数。
相关问题
tengine2.3.3生成的日志以这种格式结尾2022-01-01 15:00:00.000,每个日志最大5MB,自动清理1个月以前的日志,日志包括access和error日志,给出详细配置教程
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
tengine2.3.3只保留1个月的日志,并且日志文件最大为5MB,包括access.log和error.log
Tengine 2.3.3可以通过配置nginx.conf文件来实现只保留1个月的日志,并且日志文件最大为5MB。具体配置如下:
- 在http模块中添加 log_format 来指定日志格式,如:
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
- 在server模块中添加access_log来记录访问日志,如:
access_log /var/log/nginx/access.log main;
- 在server模块中添加error_log来记录错误日志,如:
error_log /var/log/nginx/error.log;
修改完成后,可使用 logrotate来实现保留一个月的日志,并且限制文件大小为5MB。具体配置可以看这个网页,https://www.cnblogs.com/YBMX/p/11532712.html