class Lumberjack::Device
This is an abstract class for logging devices. Subclasses must implement the write
method and may implement the close
and flush
methods if applicable.
Public Instance Methods
cleanup_files!()
click to toggle source
# File lib/lumberjack/device/rolling_log_file.rb, line 110 def cleanup_files! if keep files = Dir.glob("#{path}.*").collect { |f| [f, File.ctime(f)] }.sort { |a, b| b.last <=> a.last }.collect { |a| a.first } if files.size > keep files[keep, files.length].each do |f| File.delete(f) end end end end
close()
click to toggle source
Subclasses may implement this method to close the device.
# File lib/lumberjack/device.rb, line 21 def close flush end
datetime_format()
click to toggle source
Subclasses may implement this method to get the format for log timestamps.
# File lib/lumberjack/device.rb, line 35 def datetime_format end
datetime_format=(format)
click to toggle source
Subclasses may implement this method to set a format for log timestamps.
# File lib/lumberjack/device.rb, line 39 def datetime_format=(format) end
do_once(file) { || ... }
click to toggle source
# File lib/lumberjack/device/rolling_log_file.rb, line 121 def do_once(file) begin file.flock(File::LOCK_EX) rescue SystemCallError # Most likely can't lock file because the stream is closed return end begin verify = begin file.lstat rescue nil end # Execute only if the file we locked is still the same one that needed to be rolled yield if verify && verify.ino == @file_inode && verify.size > 0 ensure begin file.flock(File::LOCK_UN) rescue nil end end end
flush()
click to toggle source
Subclasses may implement this method to flush any buffers used by the device.
# File lib/lumberjack/device.rb, line 31 def flush end
reopen(logdev = nil)
click to toggle source
Subclasses may implement this method to reopen the device.
# File lib/lumberjack/device.rb, line 26 def reopen(logdev = nil) flush end
write(entry)
click to toggle source
Subclasses must implement this method to write a LogEntry
.
# File lib/lumberjack/device.rb, line 16 def write(entry) raise NotImplementedError end