Log rotation

Tags:

#1 amani

What is the best way to do a log rotation?

I'm using fileop and I wanted log rotation at midnight, but it hasn't been working. Would it be better to move the Schedule to the Output section?

<Extension fileop>
    Module      xm_fileop

    # Check the size of our log file every hour and rotate if it is larger than 1Mb
    <Schedule>
        Every   1 hour
        Exec    if (file_size('%LOGFILE%') >= 1M) file_cycle('%LOGFILE%', 500);
    </Schedule>

    # Rotate our log file every week on sunday at midnight
    <Schedule>
        When    @midnight
        Exec    file_cycle('%LOGFILE%', 500);
    </Schedule>
</Extension>

#2 b0ti Nxlog ✓
#1 amani
What is the best way to do a log rotation? I'm using fileop and I wanted log rotation at midnight, but it hasn't been working. Would it be better to move the Schedule to the Output section? <Extension fileop>     Module      xm_fileop     # Check the size of our log file every hour and rotate if it is larger than 1Mb     <Schedule>         Every   1 hour         Exec    if (file_size('%LOGFILE%') >= 1M) file_cycle('%LOGFILE%', 500);     </Schedule>     # Rotate our log file every week on sunday at midnight     <Schedule>         When    @midnight         Exec    file_cycle('%LOGFILE%', 500);     </Schedule> </Extension>

The above is for rotating nxlog.log.

This should also work for files created with om_file but in that case you will need to also call reopen() from inside the Output block.