Class: Vedeu::Logging::LocklessLogDevice Private
- Inherits:
-
Logger::LogDevice
- Object
- Logger::LogDevice
- Vedeu::Logging::LocklessLogDevice
- Defined in:
- lib/vedeu/logging/lockless_log_device.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Ensures we can always write to the log file by creating a lock-less log device.
Instance Attribute Summary collapse
- #log ⇒ String readonly protected private
Instance Method Summary collapse
- #closable? ⇒ Boolean private private
- #close ⇒ void private
-
#initialize(log = nil) ⇒ Vedeu::Logging::LocklessLogDevice
constructor
private
Returns a new instance of Vedeu::Logging::LocklessLogDevice.
- #open_logfile(log) ⇒ void private private
- #writable? ⇒ Boolean private private
- #write(message) ⇒ void private
Constructor Details
#initialize(log = nil) ⇒ Vedeu::Logging::LocklessLogDevice
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Vedeu::Logging::LocklessLogDevice.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/vedeu/logging/lockless_log_device.rb', line 18 def initialize(log = nil) @filename = nil @log = log if writable? && closeable? @dev = log else @dev = open_logfile(log) @dev.sync = true @filename = log end end |
Instance Attribute Details
#log ⇒ String (readonly, protected)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
53 54 55 |
# File 'lib/vedeu/logging/lockless_log_device.rb', line 53 def log @log end |
Instance Method Details
#closable? ⇒ Boolean (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
58 59 60 |
# File 'lib/vedeu/logging/lockless_log_device.rb', line 58 def closable? log.respond_to?(:close) end |
#close ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
43 44 45 46 47 |
# File 'lib/vedeu/logging/lockless_log_device.rb', line 43 def close @dev.close rescue nil end |
#open_logfile(log) ⇒ void (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/vedeu/logging/lockless_log_device.rb', line 64 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 |
#writable? ⇒ Boolean (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
77 78 79 |
# File 'lib/vedeu/logging/lockless_log_device.rb', line 77 def writable? log.respond_to?(:write) end |
#write(message) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
35 36 37 38 39 40 |
# File 'lib/vedeu/logging/lockless_log_device.rb', line 35 def write() @dev.write() rescue StandardError => exception warn("log writing failed. #{exception}") end |