epimorphics / json-rails-logger

A custom rails logger that outputs JSON instead of raw text
MIT License
1 stars 1 forks source link

Missing information on how to configure with Rails #6

Closed ijdickinson closed 3 years ago

ijdickinson commented 3 years ago

There's no information on how to run the logger in Rails. I tried:

# in Gemfile:
gem 'json_rails_logger', git: 'git@github.com:epimorphics/json-rails-logger.git', branch: 'dev'
# in development.rb:
unless ENV['RAILS_LOG_CLASSIC'].present?
  logger = JsonRailsLogger::Logger.new

  config.logger = logger
end

But this resulted in an error:

     7: from /home/ian/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/bundler/gems/json-rails-logger-33bb90926728/lib/json_rails_logger/logger.rb:14:in `initialize'
     6: from /home/ian/.rbenv/versions/2.7.2/lib/ruby/2.7.0/logger.rb:389:in `initialize'
     5: from /home/ian/.rbenv/versions/2.7.2/lib/ruby/2.7.0/logger.rb:389:in `new'
     4: from /home/ian/.rbenv/versions/2.7.2/lib/ruby/2.7.0/logger/log_device.rb:18:in `initialize'
     3: from /home/ian/.rbenv/versions/2.7.2/lib/ruby/2.7.0/logger/log_device.rb:86:in `set_dev'
     2: from /home/ian/.rbenv/versions/2.7.2/lib/ruby/2.7.0/logger/log_device.rb:95:in `open_logfile'
     1: from /home/ian/.rbenv/versions/2.7.2/lib/ruby/2.7.0/logger/log_device.rb:95:in `open'
/home/ian/.rbenv/versions/2.7.2/lib/ruby/2.7.0/logger/log_device.rb:95:in `initialize': no implicit conversion of Hash into String (TypeError)

So two things please:

bogdanadrianmarc commented 3 years ago

Spent some time looking into the errors, but apparently the fix was much simpler than that. logger = JsonRailsLogger::Logger.new should be logger = JsonRailsLogger::Logger.new(STDOUT) and that should fix the errors.

I'm also going to leave this issue open and reference it in a PR updating the README file with instructions

ijdickinson commented 3 years ago

Confirm that passing the output stream works.