Logger::LogDevice (Class)

In: logger.rb
Parent: Object

LogDevice — Logging device.

Methods

close   new   write  

Constants

SiD = 24 * 60 * 60

Attributes

dev  [R] 
filename  [R] 

Public Class methods

Synopsis

  Logger::LogDev.new(name, :shift_age => 'daily|weekly|monthly')
  Logger::LogDev.new(name, :shift_age => 10, :shift_size => 1024*1024)

Args

name:A String (representing a filename) or an IO object (actually, anything that responds to write and close). If a filename is given, then that file is opened for writing (and appending if it already exists), with sync set to true.
opts:Contains optional arguments for rolling ("shifting") the log file. :shift_age is either a description (e.g. ‘daily’), or an integer number of log files to keep. shift_size is the maximum size of the log file, and is only significant is a number is given for shift_age.

These arguments are only relevant if a filename is provided for the first argument.

Description

Creates a LogDevice object, which is the target for log messages. Rolling of log files is supported (only if a filename is given; you can’t roll an IO object). The beginning of each file created by this class is tagged with a header message.

This class is unlikely to be used directly; it is a backend for Logger.

[Source]

# File logger.rb, line 492
    def initialize(log = nil, opt = {})
      @dev = @filename = @shift_age = @shift_size = nil
      if log.respond_to?(:write) and log.respond_to?(:close)
        @dev = log
      else
        @dev = open_logfile(log)
        @dev.sync = true
        @filename = log
        @shift_age = opt[:shift_age] || 7
        @shift_size = opt[:shift_size] || 1048576
      end
    end

Public Instance methods

Close the logging device.

[Source]

# File logger.rb, line 526
    def close
      @dev.close
    end

Log a message. If needed, the log file is rolled and the new file is prepared. Log device is not locked. Append open does not need to lock file but on an OS which supports multi I/O, records could possibly be mixed.

[Source]

# File logger.rb, line 511
    def write(message)
      if shift_log?
        begin
          shift_log
        rescue
          raise Logger::ShiftingError.new("Shifting failed. #{$!}")
        end
      end

      @dev.write(message) 
    end

[Validate]