Skip to content

End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

class method

Logger.new

Logger.new(logdev, shift_age = 0, shift_size = 1048576)
Logger.new(logdev, shift_age = 'weekly')
Logger.new(logdev, level: :info)
Logger.new(logdev, progname: 'progname')
Logger.new(logdev, formatter: formatter)
Logger.new(logdev, datetime_format: '%Y-%m-%d %H:%M:%S')

Args

logdev

The log device. This is a filename (String), IO object (typically STDOUT, STDERR, or an open file), nil (it writes nothing) or File::NULL (same as nil).

shift_age

Number of old log files to keep, or frequency of rotation (daily, weekly or monthly). Default value is 0, which disables log file rotation.

shift_size

Maximum logfile size in bytes (only applies when shift_age is a positive Integer). Defaults to 1048576 (1MB).

level

Logging severity threshold. Default values is Logger::DEBUG.

progname

Program name to include in log messages. Default value is nil.

formatter

Logging formatter. Default values is an instance of Logger::Formatter.

datetime_format

Date and time format. Default value is ‘%Y-%m-%d %H:%M:%S’.

binmode

Use binary mode on the log device. Default value is false.

shift_period_suffix

The log file suffix format for daily, weekly or monthly rotation. Default is ‘%Y%m%d’.

Description

Create an instance.

See also #<< #add also in 3.4 · 3.3 · 3.2 · 3.0