Maintenance of Ruby 2.0.0 ended on February 24, 2016. Read more

In Files

  • logger.rb

Parent

Methods

Logger::LogDevice

Device used for logging messages.

Constants

SiD

Attributes

dev[R]
filename[R]

Public Class Methods

new(log = nil, opt = {}) click to toggle source
 
               # File logger.rb, line 545
def initialize(log = nil, opt = {})
  @dev = @filename = @shift_age = @shift_size = nil
  @mutex = LogDeviceMutex.new
  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() click to toggle source
 
               # File logger.rb, line 580
def close
  begin
    @mutex.synchronize do
      @dev.close rescue nil
    end
  rescue Exception
    @dev.close rescue nil
  end
end
            
write(message) click to toggle source
 
               # File logger.rb, line 559
def write(message)
  begin
    @mutex.synchronize do
      if @shift_age and @dev.respond_to?(:stat)
        begin
          check_shift_log
        rescue
          warn("log shifting failed. #{$!}")
        end
      end
      begin
        @dev.write(message)
      rescue
        warn("log writing failed. #{$!}")
      end
    end
  rescue Exception => ignored
    warn("log writing failed. #{ignored}")
  end
end