Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.
/ easy_log Public archive

EasyLog was created to make it easy and quick to output detailed log messages.

License

Notifications You must be signed in to change notification settings

jclusso/easy_log

Repository files navigation

Build Status Code Climate

EasyLog

Image of a log

EasyLog was created to make it easy and quick to output detailed log messages.

Installation

Add this line to your application's Gemfile:

gem 'easy_log'

And then execute:

$ bundle

Or install it yourself as:

$ gem install easy_log

And then include at top of any class

class Customer
  include EasyLog

  def create
    ...
  end
end

For usage in sidekiq, set the logger to sidekiq's logger in the configure_server block:

Sidekiq.configure_server do |config|
  EasyLog.set_logger config.logger
end

Usage

class Customer
  include EasyLog

  def create(name, gender)
    # useful at the beginning of a method
    log :start
    # Customer#create: STARTED! w/ name: Jarrett gender: male

    # a general log message
    log 'Customer Signup from Google Campaign.'
    # Customer#create: Customer Signup Complete! w/
    # name: Jarrett gender: male


    # a simple success message
    log :success 'Customer Signup Complete!'
    # Customer#create: SUCCESS: Customer Signup Complete! w/
    # name: Jarrett gender: male

    # or an error message
    log :error, 'External API Failed To Connect!'
    # Customer#create: ERROR: External API Failed To Connect w/
    # name: Jarrett gender: male

    # pass additional parameters in
    log :error, 'External API Failed To Connect!', plan_id: '4'
    # Customer#create: ERROR: Exteranl API Failed To Connect w/
    # name: Jarrett gender: male plan_id: 4

    # will even include instance variables if found
    @customer_id = '1'
    log :success, 'Customer Signup Complete!'
    # Customer#create: SUCCESS: Customer Signup Complete! w/
    # @customer_id: 1 name: Jarrett gender: male

    # useful at the end of a method
    log :finish
    # Customer#create: FINISHED! w/ name: Jarrett gender: male
  end
end

The EasyLog.set_logger function can be used to set any class as the logger, as long as it responds to #info. In Rails apps, it will use the Rails logger as default.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/jclusso/easy_log. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

EasyLog - quickly and easily output detailed log messages
Copyright (C) 2015  Jarrett Lusso

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

About

EasyLog was created to make it easy and quick to output detailed log messages.

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages