Class: MonoLogger::LocklessLogDevice

Inherits:
LogDevice
  • Object
show all
Defined in:
lib/mono_logger.rb

Instance Method Summary collapse

Constructor Details

#initialize(log = nil) ⇒ LocklessLogDevice

Returns a new instance of LocklessLogDevice.



41
42
43
44
45
46
47
48
49
50
# File 'lib/mono_logger.rb', line 41

def initialize(log = nil)
  @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
  end
end

Instance Method Details

#closeObject



58
59
60
# File 'lib/mono_logger.rb', line 58

def close
  @dev.close rescue nil
end

#write(message) ⇒ Object



52
53
54
55
56
# File 'lib/mono_logger.rb', line 52

def write(message)
  @dev.write(message)
rescue Exception => ignored
  warn("log writing failed. #{ignored}")
end