DEV: Apply Logster.store.ignore to DiscourseLogstashLogger as well (#27819)

This commit updates `DiscourseLogstashLogger#add_with_opts` to avoid
logging messages that matches regexp patterns configured in
`Logster.store.ignore`. Those error logs are mostly triggered by clients
and do not serve any useful purpose.
This commit is contained in:
Alan Guo Xiang Tan
2024-07-10 13:51:42 +08:00
committed by GitHub
parent d4c603984f
commit c9775d5f72
2 changed files with 24 additions and 3 deletions

View File

@ -83,9 +83,14 @@ class DiscourseLogstashLogger < Logger
#
# 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 =~ /\A([^\(\)]+)\s{1}\(([\s\S]+)\)/
event["exception.class"] = $1
event["exception.message"] = $2.strip
if progname == "web-exception"
# `Logster.store.ignore` is set in the logster initializer and is an array of regex patterns.
return if Logster.store&.ignore&.any? { |pattern| pattern.match(message) }
if message =~ /\A([^\(\)]+)\s{1}\(([\s\S]+)\)/
event["exception.class"] = $1
event["exception.message"] = $2.strip
end
end
if (env = opts&.dig(:env)).present?