---
title: "Ruby 2.4 allows custom suffix of rotated log files"
description:
  "Ruby 2.4 has added ability to pass custom date format for the suffix of log
  files rotated daily, weekly or monthly"
canonical_url: "https://www.bigbinary.com/blog/ruby-2-4-allows-to-customize-suffix-of-the-rotated-log-files"
markdown_url: "https://www.bigbinary.com/blog/ruby-2-4-allows-to-customize-suffix-of-the-rotated-log-files.md"
---

# Ruby 2.4 allows custom suffix of rotated log files

Ruby 2.4 has added ability to pass custom date format for the suffix of log
files rotated daily, weekly or monthly

- Author: Sushant Mittal
- Published: June 15, 2017
- Categories: Ruby 2.4, Ruby

In Ruby, The
[Logger](http://ruby-doc.org/stdlib-2.4.0/libdoc/logger/rdoc/Logger.html#method-c-new)
class can be used for rotating log files daily, weekly or monthly.

```ruby

daily_logger = Logger.new('foo.log', 'daily')

weekly_logger = Logger.new('foo.log', 'weekly')

monthly_logger = Logger.new('foo.log', 'monthly')

```

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

```ruby

foo.log.20170615

```

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](https://github.com/ruby/ruby/commit/2c6f15b1ad90af37d7e0eefff7b3f5262e0a4c0b)
to customize the suffix format by passing an extra argument
`shift_period_suffix`.

```ruby

# Ruby 2.4

logger = Logger.new('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.

```ruby

foo.log.15-06-2017

```

## Links

- [Human page](https://www.bigbinary.com/blog/ruby-2-4-allows-to-customize-suffix-of-the-rotated-log-files)
