rails_semantic_logger icon indicating copy to clipboard operation
rails_semantic_logger copied to clipboard

File appender ignoring formatter?

Open mhellsten-ml opened this issue 2 years ago • 2 comments

Environment

  • Ruby Version: 2.5.8
  • Semantic Logger Version: 4.12
  • Application/framework: Rails 5.2.4
  • Rails Semantic Logger Version: 4.11
  • Rails configuration: config.semantic_logger.add_appender(file_name: "log/#{Rails.env}.json", formatter: :json) in development.rb

Expected Behavior

A log/development.json file with json-formatted output

Actual Behavior

The log/development.json file appears and gets content, but it's the default color formatter, not json. What could I be doing wrong?

Thank you!

mhellsten-ml avatar Nov 15 '22 20:11 mhellsten-ml

I was able to reproduce this on Rails 6.1.7 with Ruby 2.5.8. and Rails 6.1.7 with Ruby 2.6.6 too. If I add the appender using config.semantic_logger.add_appender as indicated above in application.rb or environments/<environment>.rb (as suggested by the documentation, if I understand correctly), the appender formatter gets clobbered somehow. If, instead, I add it using SemanticLogger.add_appender(file_name: "log/#{Rails.env}.json", formatter: :json) in an initializer, it seems to work as expected.

Any thoughts why that's happening, and does it make sense to leave it like I have it now?

mhellsten-ml avatar Nov 16 '22 02:11 mhellsten-ml