This blog is part of our Ruby 2.4 series.

In Ruby, The Logger class can be used for rotating log files daily, weekly or monthly.

daily_logger ='foo.log', 'daily')

weekly_logger ='foo.log', 'weekly')

monthly_logger ='foo.log', 'monthly')

At the end of the specified period, Ruby will change the file extension of the log file as follows:


The format of the suffix for the rotated log file is %Y%m%d. In Ruby 2.3, there was no way to customize this suffix format.

Ruby 2.4 added the ability to customize the suffix format by passing an extra argument shift_period_suffix.

# Ruby 2.4

logger ='foo.log', 'weekly', shift_period_suffix: '%d-%m-%Y')

Now, suffix of the rotated log file will use the custom date format which we passed.