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 configuration

  • Logs to STDOUT
  • Contains classname

Excerpt:

def self.configure_logger_for(classname)
  logger = Logger.new(STDOUT)
  logger.progname = classname
  logger
end

Possible improvements

  • Make logger configurable (especially the output)

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'

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

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.