Skip to content

Commit

Permalink
Add json log formatter to standard logger
Browse files Browse the repository at this point in the history
  • Loading branch information
suprjinx committed Oct 23, 2024
1 parent d87c082 commit 13d8b89
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
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
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

0 comments on commit 13d8b89

Please sign in to comment.