LoggerJson is a gem written in Ruby that adds new functionality, without changing the function of the Logger or Syslog::Logger classes methods, which creates the logs in the json format.
Getting started
LoggerJson's installation is pretty standard:
gem install logger_json
Or add the following line to your Gemfile
:
gem 'logger_json'
Then run bundle install
Just initialize the gem and watch the magic happen
require 'logger_json'
If you don't create a Logger with specified file, don't be discouraged, you can set a environment var or ruby path var
ENV['LOG_PATH'] #or
LoggerJson::Text::PATH = 'path_you_desire'
To return the correct line of executed code, set the variable LoggerJson::Text::ROOT_FOLDER
LoggerJson::Text::ROOT_FOLDER = '/r7/'
Parameters
{
date: "2020-02-05T13:46:11.026134758+00:00", #iso8601
host: "172.0.0.10",
thread_id: '51515151515151',
file: '.././component.rb:32:in `rescue in render',
level: 'info',
message: 'LoggerJson is a gem written in Ruby that ...'
}
To add parameters in the json logger
- Logger class
more_params = {key1: data, key2: data ... keyN: data}
Logger.new('output').warn(message, more_params)
- Syslog::Logger class
LoggerJson::Text::PATH = './logs/logs-json.log'
logger = Syslog::Logger.new 'logger_json'
more_params = {key1: data, key2: data ... keyN: data}
logger.info(message, more_params)
Compatibility
- Ruby 1.9+
Running tests
Download the source code
LoggerJson uses Mini Test as test framework.
Ruby version > 2.0
Running all tests:
ruby test/test.rb
- Running tests for a specific file:
ruby test/create_file_spec.rb
Changelog
LoggerJson changelog is available here.
Copyright
Copyright (c) 2020