syslog rotation - dated file naming

Tags:

#1 Biggsy

I'm struggling with rotating syslog files at midnight so that they are named "YYYY-MM-DD.log" (and contain log records for that date).

I wonder if anyone has an example of the best way to achieve this.  The manual could use an example like this.

Thanks

Phil

 

 

#2 atmosx (Last updated )
#1 Biggsy
I'm struggling with rotating syslog files at midnight so that they are named "YYYY-MM-DD.log" (and contain log records for that date). I wonder if anyone has an example of the best way to achieve this.  The manual could use an example like this. Thanks Phil    

Hi Biggsy,

There are ways to rotate files. You can go like:

<Extension _fileop>
    Module      xm_fileop
    # Rotate our log file every day
    <Schedule>
      When @daily
      Exec    if file_exists(%LOGFILE%) file_cycle(%LOGFILE%, 8);
    </Schedule>
</Extension>

 

This will rename the file, to <filename>.1 which is the standard format for log rotation. Then you can use "om_exec" module to manage to rename the file to what you want. To get yesterday's date you can use this bash command $(date  --date="1 days ago" +"%Y-%m-%d").

 

UPDATE: You can try using:

 strftime(now() - 24*60*60, "%Y%m%d%H%M%S");