
Security News
Scaling Socket from Zero to 10,000+ Organizations
Socket CEO Feross Aboukhadijeh shares lessons from scaling a developer security startup to 10,000+ organizations in this founder interview.
lumberjack_aziz_light
Advanced tools
= Lumberjack
Lumberjack is a simple, powerful, and fast logging implementation in Ruby. It uses nearly the same API as the Logger class in the Ruby standard library and as ActiveSupport::BufferedLogger in Rails.
== Usage
This code aims to be extremely simple to use. The core interface it the Lumberjack::Logger which is used to log messages (which can be any object) with a specified Severity. Each logger has a level associated with it and messages are only written if their severity is greater than or equal to the level.
logger = Lumberjack::Logger.new("logs/application.log") # Open a new log file with INFO level logger.info("Begin request") logger.debug(request.params) # Message not written unless the level is set to DEBUG begin # do something rescue => exception logger.error(exception) raise end logger.info("End request")
This is all you need to know to log messages.
== Features
=== Meta data
When messages are added to the log, additional data about the message is kept in a Lumberjack::LogEntry. This means you don't need to worry about adding the time or process id to your log messages as they will be automatically recorded.
The following information is recorded for each message:
=== Units Of Work
A unit of work can be used to tie together all log messages within a block. This can be very useful to isolate a group of messages that represent one path through the system. For instance, in a web application, a single request represents a natural unit of work, and when you are looking through a log file, it is useful to see the entire set of log entries as a unit instead of interspersed with messages from other concurrent requests.
Lumberjack.unit_of_work do logger.info("Begin request") yield logger.info("End request") end
=== Pluggable Devices
When a Logger logs a LogEntry, it sends it to a Lumberjack::Device. Lumberjack comes with a variety of devices for logging to IO streams or files.
If you'd like to send you log to a different kind of output, you just need to extend the Device class and implement the +write+ method. Or check out these plugins:
=== Customize Formatting
When a message is logged, it is first converted into a string. You can customize how it is converted by adding mappings to a Formatter.
logger.formatter.add(Hash, :pretty_print) # use the Formatter::PrettyPrintFormatter for all Hashes logger.formatter.add(MyClass){|obj| "#{obj.class}@#{obj.id}"} # use a block to provide a custom format
If you use the built in devices, you can also customize the Template used to format the LogEntry.
Lumberjack::Logger.new("application.log", :time_format => "%m/%d/%Y %H:%M:%S")
Lumberjack::Logger.new("application.log", :template => ":time - :message")
template = lambda{|e| "#{e.severity_label[0, 1]} #{e.time} - #{e.message}"} Lumberjack::Logger.new("application.log", :template => template)
=== Buffered Performance
The logger has hooks for devices that support buffering to increase performance by batching physical writes. Log entries are not guaranteed to be written until the Lumberjack::Logger#flush method is called.
You can use the :flush_seconds option on the logger to periodically flush the log. This is usually a good idea so you can more easily debug hung processes. Without periodic flushing, a process that hangs may never write anything to the log because the messages are sitting in a buffer. By turning on periodic flushing, the logged messages will be written which can greatly aid in debugging the problem.
The built in stream based logging devices use an internal buffer. The size of the buffer (in bytes) can be set with the :buffer_size options when initializing a logger. The default behavior is to not to buffer.
logger = Lumberjack::Logger.new("application.log", :buffer_size => 8192)
logger = Lumberjack::Logger.new("application.log", :buffer_size => 0)
=== Automatic Log Rolling
The built in devices include two that can automatically roll log files based either on date or on file size. When a log file is rolled, it will be renamed with a suffix and a new file will be created to receive new log entries. This can keep your log files from growing to unusable sizes and removes the need to schedule an external process to roll the files.
There is a similar feature in the standard library Logger class, but the implementation here is safe to use with multiple processes writing to the same log file.
FAQs
Unknown package
We found that lumberjack_aziz_light demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CEO Feross Aboukhadijeh shares lessons from scaling a developer security startup to 10,000+ organizations in this founder interview.

Research
Socket Threat Research maps a rare inside look at OtterCookie’s npm-Vercel-GitHub chain, adding 197 malicious packages and evidence of North Korean operators.

Research
Socket researchers identified a malicious Chrome extension that manipulates Raydium swaps to inject an undisclosed SOL transfer, quietly routing fees to an attacker wallet.