log_toolbox

Ruby gem for logging

LogToolbox

Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file lib/log_toolbox. To experiment with that code, run bin/console for an interactive prompt.

TODO: Delete this and the text above, and describe your gem

Installation

Add this line to your application's Gemfile:

gem 'log_toolbox'

And then execute:

$ bundle

Or install it yourself as:

$ gem install log_toolbox

Usage

Create a rails initializer 'config/initializers/lograge.rb' with content

LogToolbox::LogrageConfig.configure

At your application_controller, include LogToolbox::LogPayload

class ApplicationController < ActionController::API
  include LogToolbox::LogPayload
end

Now your application log was converted to json pattern.

Log at controller

You can log additional informations on your controller with methods log_info, log_warn, log_error and log_critical example at your user_controller.rb

def index
  log_info('Getting all users') # => {"id":null,"event_at":"2019-05-21 17:41:59 -0300","level":"INFO","service_name":"logging","version":"1.0.1","origin_ipv4":"127.0.0.1","destination_ipv4":"localhost","username":null,"message":"Getting all users"}

  @users = User.all

  render json: @users
end

Log whatever you want

LogToolbox::LogSimple.log_info('system was here') # => {"event_at":"2019-05-21 17:41:59 -0300","level":"INFO","service_name":"logging","version":"1.0.1","message":"system was here"}

Also you can log with same methods log_info, log_warn, log_error and log_critical

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/[USERNAME]/log_toolbox.

License

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