Class: Vedeu::MonoLogger::LocklessLogDevice
- Inherits:
-
LogDevice
- Object
- LogDevice
- Vedeu::MonoLogger::LocklessLogDevice
- Defined in:
- lib/vedeu/support/log.rb
Instance Method Summary collapse
- #add_log_header(file) ⇒ Object private
- #close ⇒ Object
- #create_logfile(filename) ⇒ Object private
-
#initialize(log = nil) ⇒ LocklessLogDevice
constructor
A new instance of LocklessLogDevice.
- #open_logfile(filename) ⇒ Object private
- #write(message) ⇒ Object
Constructor Details
#initialize(log = nil) ⇒ LocklessLogDevice
Returns a new instance of LocklessLogDevice.
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/vedeu/support/log.rb', line 31 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
#add_log_header(file) ⇒ Object (private)
69 70 71 72 73 |
# File 'lib/vedeu/support/log.rb', line 69 def add_log_header(file) file.write( "# Logfile created on %s by %s\n" % [Time.now.to_s, Logger::ProgName] ) end |
#close ⇒ Object
48 49 50 |
# File 'lib/vedeu/support/log.rb', line 48 def close @dev.close rescue nil end |
#create_logfile(filename) ⇒ Object (private)
62 63 64 65 66 67 |
# File 'lib/vedeu/support/log.rb', line 62 def create_logfile(filename) logdev = open(filename, (File::WRONLY | File::APPEND | File::CREAT)) logdev.sync = true add_log_header(logdev) logdev end |
#open_logfile(filename) ⇒ Object (private)
54 55 56 57 58 59 60 |
# File 'lib/vedeu/support/log.rb', line 54 def open_logfile(filename) if (FileTest.exist?(filename)) open(filename, (File::WRONLY | File::APPEND)) else create_logfile(filename) end end |
#write(message) ⇒ Object
42 43 44 45 46 |
# File 'lib/vedeu/support/log.rb', line 42 def write() @dev.write() rescue Exception => ignored warn("log writing failed. #{ignored}") end |