Class | Lumberjack::Logger |
In: |
lib/lumberjack/logger.rb
|
Parent: | Object |
Logger is a thread safe logging object. It has a compatible API with the Ruby standard library Logger class, the Log4r gem, and ActiveSupport::BufferedLogger.
logger = Lumberjack::Logger.new logger.info("Starting processing") logger.debug("Processing options #{options.inspect}") logger.fatal("OMG the application is on fire!")
Log entries are written to a logging Device if their severity meets or exceeds the log level.
Devices may use buffers internally and the log entries are not guaranteed to be written until you call the flush method. Sometimes this can result in problems when trying to track down extraordinarily long running sections of code since it is likely that none of the messages logged before the long running code will appear in the log until the entire process finishes. You can set the +:flush_seconds+ option on the constructor to force the device to be flushed periodically. This will create a new monitoring thread, but its use is highly recommended.
Each log entry records the log message and severity along with the time it was logged, the program name, process id, and unit of work id. The message will be converted to a string, but otherwise, it is up to the device how these values are recorded. Messages are converted to strings using a Formatter associated with the logger.
Create a new logger to log to a Device.
The device argument can be in any one of several formats.
If it is a Device object, that object will be used. If it has a write method, it will be wrapped in a Device::Writer class. If it is :null, it will be a Null device that won‘t record any output. Otherwise, it will be assumed to be file path and wrapped in a Device::LogFile class.
This method can take the following options:
All other options are passed to the device constuctor.
Add a message to the log with a given severity. The message can be either passed in the message argument or supplied with a block. This method is not normally called. Instead call one of the helper functions fatal, error, warn, info, or debug.
The severity can be passed in either as one of the Severity constants, or as a Severity label.
logger.add(Lumberjack::Severity::ERROR, exception) logger.add(Lumberjack::Severity::INFO, "Request completed") logger.add(:warn, "Request took a long time") logger.add(Lumberjack::Severity::DEBUG){"Start processing with options #{options.inspect}"}
Set the program name that is associated with log messages. If a block is given, the program name will be valid only within the block.
Log a message when the severity is not known. Unknown messages will always appear in the log. The message can be passed in either the message argument or in a block.