From 989600c5905c943f63b9238e4bf07812344838ed Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Mon, 10 Mar 2025 11:52:28 -0400 Subject: [PATCH] Configure structured JSON logging This configuration is emulating what we do in HEY. --- Gemfile | 3 ++- Gemfile.lock | 9 +++++++++ config/environments/production.rb | 3 +++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 6b7f73887..b06cf0c25 100644 --- a/Gemfile +++ b/Gemfile @@ -28,9 +28,10 @@ gem "redcarpet" gem "rouge" gem "jbuilder" -# Telemetry +# Telemetry and logging gem "sentry-ruby" gem "sentry-rails" +gem "rails_structured_logging", bc: "rails-structured-logging" group :development, :test do gem "debug" diff --git a/Gemfile.lock b/Gemfile.lock index e5ceacaf0..bbd9718ed 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,3 +1,11 @@ +GIT + remote: https://github.com/basecamp/rails-structured-logging + revision: 0c2d45dd98c92156cc419e75cdad2aa903290d82 + specs: + rails_structured_logging (0.2.0) + json + rails (>= 6.0.0) + GIT remote: https://github.com/rails/rails.git revision: 5520bd835e3724ffafe3f719f9aafe951567f2f3 @@ -420,6 +428,7 @@ DEPENDENCIES propshaft puma (>= 5.0) rails! + rails_structured_logging! redcarpet rouge rqrcode diff --git a/config/environments/production.rb b/config/environments/production.rb index 7dc9258a5..4fd23bc8e 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -50,6 +50,9 @@ Rails.application.configure do .tap { |logger| logger.formatter = ::Logger::Formatter.new } .then { |logger| ActiveSupport::TaggedLogging.new(logger) } + # Structured JSON logging + config.structured_logging.logger = ActiveSupport::Logger.new(STDOUT) + # Prepend all log lines with the following tags. config.log_tags = [ :request_id ]