Method: Logger#initialize

Defined in:
lib/logger.rb

#initialize(logdev, shift_age = 0, shift_size = 1048576, level: DEBUG, progname: nil, formatter: nil, datetime_format: nil, binmode: false, shift_period_suffix: '%Y%m%d') ⇒ Logger

:call-seq:

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.



380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
# File 'lib/logger.rb', line 380

def initialize(logdev, shift_age = 0, shift_size = 1048576, level: DEBUG,
               progname: nil, formatter: nil, datetime_format: nil,
               binmode: false, shift_period_suffix: '%Y%m%d')
  self.level = level
  self.progname = progname
  @default_formatter = Formatter.new
  self.datetime_format = datetime_format
  self.formatter = formatter
  @logdev = nil
  if logdev && logdev != File::NULL
    @logdev = LogDevice.new(logdev, shift_age: shift_age,
      shift_size: shift_size,
      shift_period_suffix: shift_period_suffix,
      binmode: binmode)
  end
end