Class: Vedeu::Logging::LocklessLogDevice
- Inherits:
-
Logger::LogDevice
- Object
- Logger::LogDevice
- Vedeu::Logging::LocklessLogDevice
- Defined in:
- lib/vedeu/logging/lockless_log_device.rb
Overview
Ensures we can always write to the log file by creating a lock-less log device.
Instance Method Summary collapse
- #close ⇒ void
-
#initialize(log = nil) ⇒ Vedeu::Logging::LocklessLogDevice
constructor
Returns a new instance of Vedeu::Logging::LocklessLogDevice.
- #open_logfile(log) ⇒ void private
- #write(message) ⇒ void
Constructor Details
#initialize(log = nil) ⇒ Vedeu::Logging::LocklessLogDevice
Returns a new instance of Vedeu::Logging::LocklessLogDevice.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/vedeu/logging/lockless_log_device.rb', line 14 def initialize(log = nil) @dev = nil @filename = nil if log.respond_to?(:write) && log.respond_to?(:close) @dev = log else @dev = open_logfile(log) @dev.sync = true @filename = log end end |
Instance Method Details
#close ⇒ void
This method returns an undefined value.
39 40 41 42 43 |
# File 'lib/vedeu/logging/lockless_log_device.rb', line 39 def close @dev.close rescue nil end |
#open_logfile(log) ⇒ void (private)
This method returns an undefined value.
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/vedeu/logging/lockless_log_device.rb', line 49 def open_logfile(log) if FileTest.exist?(log) open(log, (File::WRONLY | File::APPEND)) else logdev = open(log, (File::WRONLY | File::APPEND | File::CREAT)) logdev.sync = true logdev end end |
#write(message) ⇒ void
This method returns an undefined value.
31 32 33 34 35 36 |
# File 'lib/vedeu/logging/lockless_log_device.rb', line 31 def write() @dev.write() rescue StandardError => exception warn("log writing failed. #{exception}".freeze) end |