From 6f3475c7fe66d03ee257aa3e8939bea259e1c6c0 Mon Sep 17 00:00:00 2001 From: Dick Davis Date: Sat, 14 Oct 2023 00:03:17 -0500 Subject: [PATCH] Add support for replacing Rails logger (#45) * Add support for silencer * Add documentation * Update version * Update Gemfile.lock --- CHANGELOG.md | 11 +++++++++-- Gemfile.lock | 2 +- README.md | 11 +++++++++++ lib/event_logger_rails/json_logger.rb | 2 ++ lib/event_logger_rails/version.rb | 2 +- 5 files changed, 24 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3fe36ac..2dbb58b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -## [0.3.0] +## [0.3.1] - 2023-10-14 + +### Added + +- Added support for using `EventLoggerRails::JsonLogger` as a Rails logger replacement. + +## [0.3.0] - 2023-10-05 ### Added @@ -64,7 +70,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Initial release -[Unreleased]: https://github.com/d3d1rty/event_logger_rails/compare/0.3.0...HEAD +[Unreleased]: https://github.com/d3d1rty/event_logger_rails/compare/0.3.1...HEAD +[0.3.0]: https://github.com/d3d1rty/event_logger_rails/compare/0.3.0...0.3.1 [0.3.0]: https://github.com/d3d1rty/event_logger_rails/compare/0.2.1...0.3.0 [0.2.1]: https://github.com/d3d1rty/event_logger_rails/compare/0.2.0...0.2.1 [0.2.0]: https://github.com/d3d1rty/event_logger_rails/compare/0.1.0...0.2.0 diff --git a/Gemfile.lock b/Gemfile.lock index 8c449d3..9c8a586 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - event_logger_rails (0.3.0) + event_logger_rails (0.3.1) rails (>= 7.0.0) GEM diff --git a/README.md b/README.md index 93d0b35..1a0932e 100644 --- a/README.md +++ b/README.md @@ -344,6 +344,17 @@ Rails.application.configure do |config| end ``` +You can also configure the Rails logger to use `EventLoggerRails::JsonLogger` to render structured logs in JSON format with the additional app and request data. + +```ruby +Rails.application.configure do + config.colorize_logging = false + config.log_level = ENV.fetch('RAILS_LOG_LEVEL', :info) + logger = EventLoggerRails::JsonLogger.new($stdout) + config.logger = ActiveSupport::TaggedLogging.new(logger) +end +``` + ## Contributing Your inputs echo in this realm. Venture forth and materialize your thoughts through a PR. diff --git a/lib/event_logger_rails/json_logger.rb b/lib/event_logger_rails/json_logger.rb index e3c7ff2..89b8c23 100644 --- a/lib/event_logger_rails/json_logger.rb +++ b/lib/event_logger_rails/json_logger.rb @@ -4,6 +4,8 @@ module EventLoggerRails ## # Writes log entries in JSON format class JsonLogger < ::Logger + include ActiveSupport::LoggerSilence + def initialize(...) super(...) @formatter = proc do |level, timestamp, _progname, message| diff --git a/lib/event_logger_rails/version.rb b/lib/event_logger_rails/version.rb index 427fd34..0edbb4b 100644 --- a/lib/event_logger_rails/version.rb +++ b/lib/event_logger_rails/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module EventLoggerRails - VERSION = '0.3.0' + VERSION = '0.3.1' end