Class: Lumberjack::Device::LogFile
- Inherits:
-
Writer
- Object
- Lumberjack::Device
- Writer
- Lumberjack::Device::LogFile
- Defined in:
- lib/lumberjack/device/log_file.rb
Overview
A file-based logging device that extends the Writer device with automatic log rotation capabilities. This device wraps Ruby’s standard Logger::LogDevice to provide file size-based and time-based log rotation while maintaining compatibility with the Lumberjack device interface.
The device supports all the rotation features available in Ruby’s Logger, including maximum file size limits, automatic rotation based on age, and automatic cleanup of old log files. This makes it suitable for production environments where log management is crucial.
Direct Known Subclasses
Constant Summary
Constants inherited from Writer
Writer::EDGE_WHITESPACE_PATTERN
Instance Attribute Summary
Attributes inherited from Writer
Instance Method Summary collapse
-
#dev ⇒ IO
private
Expose the underlying stream.
-
#initialize(stream, options = {}) ⇒ LogFile
constructor
Initialize a new LogFile device with automatic log rotation capabilities.
-
#path ⇒ String
Get the file system path of the current log file.
- #reopen(logdev = nil) ⇒ Object
Methods inherited from Writer
#close, #datetime_format, #datetime_format=, #flush, #write
Methods inherited from Lumberjack::Device
#close, #datetime_format, #datetime_format=, #flush, open_device, #write
Constructor Details
#initialize(stream, options = {}) ⇒ LogFile
Initialize a new LogFile device with automatic log rotation capabilities. This constructor wraps Ruby’s Logger::LogDevice while filtering options to only pass supported parameters, ensuring compatibility across Ruby versions.
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/lumberjack/device/log_file.rb', line 53 def initialize(stream, = {}) # Filter options to only include keyword arguments supported by Logger::LogDevice#initialize supported_kwargs = ::Logger::LogDevice.instance_method(:initialize).parameters .select { |type, _| type == :key || type == :keyreq } .map { |_, name| name } = .slice(*supported_kwargs) logdev = ::Logger::LogDevice.new(stream, **) super(logdev, ) end |
Instance Method Details
#dev ⇒ IO
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.
Expose the underlying stream.
79 80 81 |
# File 'lib/lumberjack/device/log_file.rb', line 79 def dev stream.dev end |
#path ⇒ String
Get the file system path of the current log file. This method provides access to the actual file path being written to, which is useful for monitoring, log analysis tools, or other file-based operations.
71 72 73 |
# File 'lib/lumberjack/device/log_file.rb', line 71 def path stream.filename end |
#reopen(logdev = nil) ⇒ Object
83 84 85 |
# File 'lib/lumberjack/device/log_file.rb', line 83 def reopen(logdev = nil) stream.reopen(logdev) end |