EasyLogging

Ruby utility that lets you include logging anywhere easily, without redundancy.

Branch Status
Release Build Status Coverage Status Gem Version Total Downloads
Development Build Status Coverage Status

Features

  • Adds logging functionality anywhere with one, short, self-descriptive command
  • Logger works in both class and instance methods
  • Logger is specific to class and contains class name
  • Logger is configurable to use standard streams or file

Installation

Add this line to your application's Gemfile:

gem 'easy_logging'

And then execute:

$ bundle

Or install it yourself as:

$ gem install easy_logging

Usage

Add include EasyLogging to any context (e.g. a class) you want to extend with logging functionality.

require 'easy_logging'
EasyLogging.log_destination = 'app.log'

class YourClass
  include EasyLogging

  def do_something
    # ...
    logger.info 'something happened'
  end
end

class YourOtherClass
  include EasyLogging

  def self.do_something
    # ...
    logger.info 'something happened'
  end
end

YourClass.new.do_something
YourOtherClass.do_something

Output:

I, [2017-06-03T21:59:25.160686 #5900]  INFO -- YourClass: something happened
I, [2017-06-03T21:59:25.160686 #5900]  INFO -- YourOtherClass: something happened

Configuration

[Since v0.2.0]

You can configure log destination as:

EasyLogging.log_destination = 'app.log'

Otherwise it will default to STDOUT.

Important notes:

  • Log destination setting is global for all loggers
  • It is recommended to require EasyLogging and set the logger up properly in the initial setup of your application before any logging activity
  • Changing log destination on the fly will affect all future and not yet used loggers, however already used ones will log to the original destination

Feedback

Any feedback is much appreciated.

I can only tailor this project to fit use-cases I know about - which are usually my own ones. If you find that this might be the right direction to solve your problem too but you find that it's suboptimal or lacks features don't hesitate to contact me.

Please let me know if you make use of this project so that I can prioritize further efforts.

Development

This gem is developed using Bundler conventions. A good overview can be found here.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/thisismydesign/easy_logging.

License

The gem is available as open source under the terms of the MIT License.