1.下载地址
2. 解压 配置logrotate.conf文件
# sample logrotate configuration file
# use date as a suffix of the rotated file
dateext
# uncomment to enable compression of rotated log files
compress
# this example will rotate the c:\test.log file daily and keep 5 rotations.
# there is also an example prerotate script that will print the current time and the parameter passed to it (which is the path to the log file)
#C:\test.log {
# rotate 5
# daily
# prerotate
# @echo off
# echo This is a test
# echo parameter pass %1
# VER | TIME > TEMP.BAT
# ECHO SET TIME=%%3>CURRENT.BAT
# DEL TEMP.BAT
# DEL CURRENT.BAT
# ECHO It's %TIME% now
# endscript
#}
"C:\demo\nginx\nginx-1.20.2\logs\*.log" {
daily
rotate 10
missingok
copytruncate
compress
size 10M
noolddir
dateext
dateformat .%d-%s
}
"C:\demo\appresources\logs\*\*.log" {
daily
rotate 10
missingok
copytruncate
compress
size 10M
noolddir
dateext
dateformat .%d-%s
}
3.清理脚本 保留30天
3.1创建cleanLog.bat
# 在操作里面配置 本示例中是把exe文件与conf放在同一目录下
forfiles /p C:\demo\appresources\logs /s /d -30 /m *.* /c "cmd /c del /q /f @path"
forfiles /p C:\demo\nginx\logs /s /d -30 /m *.* /c "cmd /c del /q /f @path"
4.配置计划任务
5.参考资料
windows 下的 apache 日志如何进行分割配置?
logrotatewin
linux logrotate 配置说明