ActiveLogger
A rich logger extending the capabilities of the ActiveSupport logger
Installation
Add this line to your application's Gemfile:
gem 'active_logger'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install active_logger
Usage
Basic example
logger = ActiveLogger.new :stdout
logger.info 'test' # => test
There are 3 types:
:stdout
: Messages will be written to STDOUT:stderr
: Messages will be written to STDERR:file
: Messages will be written to a file
File example
logger = ActiveLogger.new :file, filename: 'log/development.log', keep: 30, size: 10
logger.info 'test'
# Alternative
logger = ActiveLogger.new 'log/development.log', keep: 30, size: 10
logger.info 'test'
where:
- filename - full path to logfile for writing
- keep - count of files for keeping
- size - maximum bytes for one file
Example: Block and multiple appenders
logger = ActiveLogger.new do |al|
al.appender :stdout
al.appender :file, filename: 'log/development.log', keep: 30, size: 10
end
logger.info 'test'
Example: Tagging
logger = ActiveLogger.new STDOUT
logger.tagged('API').info 'test'
# or
logger.tagged('API') do
logger.info 'test'
end
Example: Setting the Log Level
ActiveLogger.new STDOUT, level: :info
# or
ActiveLogger.new do |al|
al.level = :debug
al.appender :stdout
end
Example: Formatters
There are 2 standard formatters: :default
and :json
.
ActiveLogger.new STDOUT, formatter: :json
# or
ActiveLogger.new do |al|
al.formatter = :json
al.appender :stdout
end
# or custom formatter
class Formatter < ActiveLogger::Formatters::Base
def call(severity, , progname, msg)
"[#{severity}] [#{}] #{msg}"
end
end
ActiveLogger.new STDOUT, formatter: Formatter
Development
After checking out the repo, run bin/setup
to install dependencies. Then, run rake spec
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/jurrick/active_logger.
License
The gem is available as open source under the terms of the MIT License.