logging icon indicating copy to clipboard operation
logging copied to clipboard

Confused on configuration of retention Rolling Log files

Open ajnh opened this issue 7 years ago • 0 comments

Hi Sorry to be a pain.

Confused about how to configure the Rolling Log file appender specifically around aged retention. The examples pretty much all use 'daily'; and the comments indicate 'weekly' and 'monthly' as well. Whilst 'weekly' will be OK for some environments, in others we wanted a custom period, e.g. 2 days. Based on the comments of logging/appenders/RollingFile (rolling_file.rb), it suggests the age in seconds. Consequently, I configured the age as 60 * 60 * 24 * 2 (60 sec * 60 mins * 24 hrs * 2 days). However, 4 days later and the original logs are still around.

I'm a relative newbie to Ruby, so whilst I tried to trace the code and figure it out myself, what I am seeing is only the rolling of the log.

So, I'm thinking that whilst I have this configuration

    # Rolling log file, keeping 7 days worth, each sized up to 50 Mb
    Logging.appenders.rolling_file \
      'all',
      :filename => log_path_name.to_s,
      :level    => :debug,
      :roll_by  => 'date',
      :size     => config.all_log_max_size,    # 50G 50 * 1024 * 1024
      :age      => config.all_log_retention_age,    # 60 * 60 * 24 * 2
      :layout   => layout

this is actually saying role when it hits 50G or 2 days, rather than what I thought it was - role when it hits 50G and remove when its 2 days old.

Whilst the Rolling File implementation says the keep is number of logs, the confusion was seeded in the Logging::Logging (logging.rb) - keep = age = args.shift which implies that keep and age are synonymous.

Looked for some tests that might explain the behaviour, but couldn't see any.

So, a/ is there a way to retain for a specific period; and if so, b/ can you advise how to effect that configuration or where I can find doco / example please?

Again apologies for asking dumb questions. Andrew

PS: Great Ruby extension!

ajnh avatar Aug 03 '18 02:08 ajnh