Open gruan01 opened 8 years ago
We had a similar problem. On some servers we use only the windows event log, but on other servers we really want a log file. The default logrotate script on Ubuntu Linux uses copytruncate, so we decided to use a similar approach in Windows. The following PowerShell function can copy and truncate a Redis log file while running:
function RotateTruncateLog($log) {
$datetime = Get-Date -uformat "%Y-%m-%d" # Get Current Date and Time
$newname = "$log.$datetime"
if (Test-Path $newname)
{
Write-Host "* Output file $newname already exists, log not truncated"
return
}
Write-Host "* Copying '$log' to '$newname'"
Copy-Item $log $newname
Write-Host "* Truncating '$log'"
Clear-Content $log
}
@renaatd Thank you , it looks very good. thanks .
Hi, We have deploy Redis as windows service. And turn on syslog-enabled , set logfile as a txt file , and loglevel as warning. But there is no config section can limit log file's size or split it to muti files. Just 2 or 3 days, the log file's size will more then 200M, open it will take too long time...
I'm trying to use logrotatewin to split log file, but it has a lock by redis. logrotatewin can't do any thing...
Have any other ways ?