##################################################################
#
# cfe_internal_log_rotation
#  - Rotate logs and clean up old files so the disk doesn't get full
#
##################################################################


bundle agent cfe_internal_log_rotation
# @brief Manage CFEngine log files so they don't fill up disks
# See def.cf to enable rotation
{
  methods:

    cfengine_internal_rotate_logs::
      # CFEngine generates internal log files that need to be rotated.
      # Have a look at def.cf to enable rotation of these files
      "Rotate CFEngine log files"
        handle    => "cfe_internal_log_rotation_rotate_log_files",
        usebundle => logrotate( @(def.cfe_log_files), $(def.mpf_log_file_max_size), $(def.mpf_log_file_retention) ),
        comment => "To keep the disk from getting to full we want to rotate log
                    files when they reach $(def.mpf_log_file_max_size) in size.
                    So that we have some history , we keep
                    $(def.mpf_log_file_retention) versions.";

      "Prune old log files"
        handle    => "cfe_internal_log_rotation_prune_log_dirs",
        usebundle => prunedir( @(def.cfe_log_dirs), $(def.mpf_log_dir_retention) ),
        comment => "Scheduled activities like agent runs and reports can create
                    log files or reports that stack up over time. So that we
                    don't fill the disk, but have some historical information
                    available locally we purge log files older than
                    $(def.mpf_log_dir_retention) days.";

  reports:

    DEBUG|DEBUG_cfe_internal_log_rotation::
      "DEBUG $(this.bundle): Check CFEngine log file for rotation '$(def.cfe_log_files)'";
      "DEBUG $(this.bundle): Check CFEngine log directory for old logs in '$(def.cfe_log_dirs)' older than '$(def.mpf_log_dir_retention)' days";
}
