From d402d8f001ae097b9d11fb823f30370cf1a5ad87 Mon Sep 17 00:00:00 2001 From: "Michael J. Giarlo" Date: Mon, 24 Feb 2025 10:47:40 -0800 Subject: [PATCH] Add log formatter to application config Do this so that logger calls outside of Rack (such as those called in background jobs) pick up timestamps. --- config/application.rb | 5 +++++ config/environments/production.rb | 5 +---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/config/application.rb b/config/application.rb index 42b57925c..2a5b127ef 100644 --- a/config/application.rb +++ b/config/application.rb @@ -73,6 +73,11 @@ class Application < Rails::Application Cocina::Models::Mapping::Purl.base_url = Settings.release.purl_base_url end + # Add timestamps to all loggers (both Rack-based ones and e.g. Sidekiq's) + config.log_formatter = proc do |severity, datetime, _progname, msg| + "[#{datetime.to_fs(:iso8601)}] [#{severity}] #{msg}\n" + end + # Only loads a smaller set of middleware suitable for API only apps. # Middleware like session, flash, cookies can be added back manually. # Skip views, helpers and assets when generating a new resource. diff --git a/config/environments/production.rb b/config/environments/production.rb index e49dbad81..181361064 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -48,10 +48,7 @@ end # Prepend all log lines with the following tags. - config.log_tags = [ - ->(_request) { Time.now.iso8601 }, - :request_id - ] + config.log_tags = [:request_id] # "info" includes generic and useful information about system operation, but avoids logging too much # information to avoid inadvertent exposure of personally identifiable information (PII). If you