mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:43:33 +08:00
DEV: Add exception class and message fields to DiscourseLogstashLogger
(#27787)
This commit updates `DiscourseLogstashlogger` to add the `exception_class` and `exception_message` field to the log line when the `progname` of the log message is `web-exception` which is Logster's logging of exceptions during a web request. The `exception_class` and `exception_message` fields allows consumers of the logs to easily group logs together.
This commit is contained in:

committed by
GitHub

parent
7049838673
commit
af2bd4cc50
@ -74,6 +74,17 @@ class DiscourseLogstashLogger < Logger
|
||||
event["backtrace"] = backtrace
|
||||
end
|
||||
|
||||
# `web-exception` is a log message triggered by logster.
|
||||
# The exception class and message are extracted from the message based on the format logged by logster in
|
||||
# https://github.com/discourse/logster/blob/25375250fb8a5c312e9c55a75f6048637aad2c69/lib/logster/middleware/debug_exceptions.rb#L22.
|
||||
#
|
||||
# In theory we could get logster to include the exception class and message in opts but logster currently does not
|
||||
# need those options so we are parsing it from the message for now and not making a change in logster.
|
||||
if progname == "web-exception" && message =~ /^(\w+) \((.+)\)\n/
|
||||
event["exception.class"] = $1
|
||||
event["exception.message"] = $2
|
||||
end
|
||||
|
||||
if (env = opts&.dig(:env)).present?
|
||||
ALLOWED_HEADERS_FROM_ENV.each do |header|
|
||||
event["request.headers.#{header.downcase}"] = opts[:env][header]
|
||||
|
Reference in New Issue
Block a user