From 95112f04376738219191265b1c4e730c416c8798 Mon Sep 17 00:00:00 2001 From: Geoff Wilson Date: Thu, 24 Oct 2024 12:23:31 -0400 Subject: [PATCH] use json_tagged_logging gem --- Gemfile | 3 +++ Gemfile.lock | 4 ++++ config/initializers/logging.rb | 9 +++++---- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index 126add0..983ef67 100644 --- a/Gemfile +++ b/Gemfile @@ -22,6 +22,9 @@ gem "tzinfo-data", platforms: %i[ mswin jruby ] # Reduces boot times through caching; required in config/boot.rb gem "bootsnap", require: false +# json logging +gem "json_tagged_logger" + # Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images] # gem "image_processing", "~> 1.2" diff --git a/Gemfile.lock b/Gemfile.lock index 0f925c8..3646b5d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -112,6 +112,9 @@ GEM actionview (>= 5.0.0) activesupport (>= 5.0.0) json (2.7.2) + json_tagged_logger (0.8.0) + actionpack (>= 5.2) + activesupport (>= 5.2) jwt (2.9.3) base64 language_server-protocol (3.17.0.3) @@ -290,6 +293,7 @@ DEPENDENCIES faraday-retry interactor (~> 3.0) jbuilder + json_tagged_logger jwt ostruct puma (>= 5.0) diff --git a/config/initializers/logging.rb b/config/initializers/logging.rb index e6e15dd..a3bde5e 100644 --- a/config/initializers/logging.rb +++ b/config/initializers/logging.rb @@ -1,4 +1,5 @@ -Rails.application.config.to_prepare do - Rails.logger = ActiveSupport::Logger.new(STDOUT) - Rails.logger.formatter = JsonLogFormatter.new -end +Rails.logger = JsonTaggedLogger::Logger.new(Rails.logger) +Rails.configuration.log_tags = JsonTaggedLogger::LogTagsConfig.generate( + :request_id +) +