Skip to content
/ loog Public

Ruby object, which you can pass to other objects, where they will use it as a logger

License

Notifications You must be signed in to change notification settings

yegor256/loog

Repository files navigation

Object-Oriented Logger for Ruby

EO principles respected here DevOps By Rultor.com We recommend RubyMine

rake Gem Version Maintainability Yard Docs Test Coverage Hits-of-Code

Loog is an object-oriented logging wrapper around Ruby Logger.

First, install it:

gem install loog

Then, use it like this:

require 'loog'
Loog::VERBOSE.info('Hello, world!')

The gem is basically a provider of a few pre-configured loggers, which you can use for production (Loog::REGULAR) or for testing (Loog::VERBOSE). You can also shut it up with Loog::NULL.

There is also Loog::Buffer class that you can use for testing. It accumulates all log calls and then returns the entire output through the to_s() method.

Also, you can "tee" two loogs, with the help of Loog::Tee. For example, to record everything in a buffer and also show in the console:

require 'loog'
require 'loog/tee'
buf = Loog::Buffer.new
loog = Loog::Tee.new(Loog::VERBOSE, buf)
loog.info('Hello, world!')
assert(buf.to_s.include?('Hello'))

You can also truncate long messages with Loog::Ellipsized:

require 'loog'
require 'loog/ellipsized'
loog = Loog::Ellipsized.new(Loog::VERBOSE, 20)
loog.info('This is a very long message that will be truncated')
# prints: "This is...truncated"

You can add ANSI colors to log messages with Loog::Colorful, which prints debug messages in dark gray, warnings in orange, and errors in red:

require 'loog'
require 'loog/colorful'
loog = Loog::Colorful.new(Loog::VERBOSE)
loog.debug('This is dark gray')
loog.warn('This is orange')
loog.error('This is red')

How to contribute

Read these guidelines. Make sure your build is green before you contribute your pull request. You will need to have Ruby 2.3+ and Bundler installed. Then:

bundle update
bundle exec rake

If it's clean and you don't see any error messages, submit your pull request.

About

Ruby object, which you can pass to other objects, where they will use it as a logger

Topics

Resources

License

Stars

Watchers

Forks

Contributors 3

  •  
  •  
  •  

Languages