microsoftarchive / redis

Redis is an in-memory database that persists on disk. The data model is key-value, but many different kind of values are supported: Strings, Lists, Sets, Sorted Sets, Hashes
http://redis.io
Other
20.81k stars 5.37k forks source link

Log file is too big #491

Open gruan01 opened 8 years ago

gruan01 commented 8 years ago

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 ?

renaatd commented 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
}
gruan01 commented 8 years ago

@renaatd Thank you , it looks very good. thanks .