# log_toolbox Ruby gem for logging ======= # LogToolbox ## Installation Add this line to your application's Gemfile: ```ruby 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 ```ruby LogToolbox::LogrageConfig.configure ``` At your application_controller, include LogToolbox::LogPayload ```ruby 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 ```ruby 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 ```ruby 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_debug, log_info, log_warn, log_error and log_critical ### Log routes ## Add routes config to manage your log level At your 'routes.rb' add log routes ```ruby Rails.application.routes.draw do log_routes end ``` You can change your application log doing a POST at /log/change_level ```json { "level": "FATAL" } ``` You can test your application log doing a GET at /log/test ## 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](https://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](https://opensource.org/licenses/MIT).