Class: Mixlib::Log::Logger::LocklessLogDevice

Inherits:
LogDevice
  • Object
show all
Defined in:
lib/mixlib/log/logger.rb

Instance Method Summary collapse

Constructor Details

#initialize(log = nil) ⇒ LocklessLogDevice

Returns a new instance of LocklessLogDevice.



60
61
62
63
64
65
66
67
68
69
# File 'lib/mixlib/log/logger.rb', line 60

def initialize(log = nil)
  @dev = @filename = @shift_age = @shift_size = nil
  if log.respond_to?(:write) && log.respond_to?(:close)
    @dev = log
  else
    @dev = open_logfile(log)
    @filename = log
  end
  @dev.sync = true
end

Instance Method Details

#closeObject



77
78
79
# File 'lib/mixlib/log/logger.rb', line 77

def close
  @dev.close rescue nil
end

#write(message) ⇒ Object



71
72
73
74
75
# File 'lib/mixlib/log/logger.rb', line 71

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