Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add request id to operational logs; use json format #63

Merged
merged 12 commits into from
Oct 25, 2024
2 changes: 1 addition & 1 deletion app/lib/audit_logger.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class AuditLogger < ActiveSupport::Logger
def initialize
super(Config[:audit_log_file])
self.formatter = AuditLogFormatter.new
self.formatter = JsonLogFormatter.new
end
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class AuditLogFormatter < ActiveSupport::Logger::SimpleFormatter
class JsonLogFormatter < ActiveSupport::Logger::SimpleFormatter
def call(severity, timestamp, _progname, message)
# request_id is unique to the life of the api request
request_id = Thread.current[:request_id]
Expand Down
8 changes: 0 additions & 8 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,6 @@
# Skip http-to-https redirect for the default health check endpoint.
# config.ssl_options = { redirect: { exclude: ->(request) { request.path == "/up" } } }

# Log to STDOUT by default
config.logger = ActiveSupport::Logger.new(STDOUT)
.tap { |logger| logger.formatter = ::Logger::Formatter.new }
.then { |logger| ActiveSupport::TaggedLogging.new(logger) }

# Prepend all log lines with the following tags.
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
# want to log everything, set the level to "debug".
Expand Down
4 changes: 4 additions & 0 deletions config/initializers/logging.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Rails.application.config.to_prepare do
Rails.logger = ActiveSupport::Logger.new(STDOUT)
Rails.logger.formatter = JsonLogFormatter.new
end
Loading