Class: Lumberjack::Device
- Inherits:
-
Object
- Object
- Lumberjack::Device
- Defined in:
- lib/lumberjack/device.rb,
lib/lumberjack/device/null.rb,
lib/lumberjack/device/multi.rb,
lib/lumberjack/device/writer.rb,
lib/lumberjack/device/log_file.rb,
lib/lumberjack/device/rolling_log_file.rb,
lib/lumberjack/device/date_rolling_log_file.rb,
lib/lumberjack/device/size_rolling_log_file.rb
Overview
This is an abstract class for logging devices. Subclasses must implement the write
method and may implement the close
and flush
methods if applicable.
Defined Under Namespace
Classes: DateRollingLogFile, LogFile, Multi, Null, RollingLogFile, SizeRollingLogFile, Writer
Instance Method Summary collapse
- #cleanup_files! ⇒ Object
-
#close ⇒ void
Subclasses may implement this method to close the device.
-
#datetime_format ⇒ String
Subclasses may implement this method to get the format for log timestamps.
-
#datetime_format=(format) ⇒ void
Subclasses may implement this method to set a format for log timestamps.
- #do_once(file) ⇒ Object
-
#flush ⇒ void
Subclasses may implement this method to flush any buffers used by the device.
-
#reopen(logdev = nil) ⇒ void
Subclasses may implement this method to reopen the device.
-
#write(entry) ⇒ void
Subclasses must implement this method to write a LogEntry.
Instance Method Details
#cleanup_files! ⇒ Object
110 111 112 113 114 115 116 117 118 119 |
# 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 ⇒ void
This method returns an undefined value.
Subclasses may implement this method to close the device.
26 27 28 |
# File 'lib/lumberjack/device.rb', line 26 def close flush end |
#datetime_format ⇒ String
Subclasses may implement this method to get the format for log timestamps.
47 48 |
# File 'lib/lumberjack/device.rb', line 47 def datetime_format end |
#datetime_format=(format) ⇒ void
This method returns an undefined value.
Subclasses may implement this method to set a format for log timestamps.
54 55 |
# File 'lib/lumberjack/device.rb', line 54 def datetime_format=(format) end |
#do_once(file) ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# 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 ⇒ void
This method returns an undefined value.
Subclasses may implement this method to flush any buffers used by the device.
41 42 |
# File 'lib/lumberjack/device.rb', line 41 def flush end |
#reopen(logdev = nil) ⇒ void
This method returns an undefined value.
Subclasses may implement this method to reopen the device.
34 35 36 |
# File 'lib/lumberjack/device.rb', line 34 def reopen(logdev = nil) flush end |
#write(entry) ⇒ void
This method returns an undefined value.
Subclasses must implement this method to write a LogEntry.
19 20 21 |
# File 'lib/lumberjack/device.rb', line 19 def write(entry) raise NotImplementedError end |