Skip to content

Commit

Permalink
Add log formatter to application config
Browse files Browse the repository at this point in the history
Do this so that logger calls outside of Rack (such as those called in background jobs) pick up timestamps.
  • Loading branch information
mjgiarlo committed Feb 24, 2025
1 parent b3b7058 commit d402d8f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 5 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 1 addition & 4 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d402d8f

Please sign in to comment.