Fixed bug: Exception logging was broken since Logger::Formatter was used and ActiveSupport::TaggedLogging::Formatter broke it.
This commit is contained in:
parent
672159a2bf
commit
46e6a6fda4
2 changed files with 30 additions and 29 deletions
|
@ -1,29 +0,0 @@
|
|||
# This customization provides the possiblity to log exception backtraces via the Rails.logger.
|
||||
#
|
||||
# @example:
|
||||
# begin
|
||||
# instance = "String :)"
|
||||
# instance.invalid_method
|
||||
# rescue => e
|
||||
# Rails.logger.error e
|
||||
# end
|
||||
# #=> undefined method `invalid_method' for "String :)":String
|
||||
# # ... backtrace ...
|
||||
# https://github.com/rails/rails/blob/308e84e982b940983b4b3d5b41b0b3ac11fbae40/activesupport/lib/active_support/logger.rb#L101
|
||||
module ActiveSupport
|
||||
class Logger < ::Logger
|
||||
class SimpleFormatter < ::Logger::Formatter
|
||||
# original behaviour:
|
||||
# rubocop:disable Lint/UnusedMethodArgument, Style/CaseEquality
|
||||
# This method is invoked when a log event occurs
|
||||
def call(severity, timestamp, progname, msg)
|
||||
return "#{String === msg ? msg : msg.inspect}\n" if !msg.is_a?(Exception)
|
||||
# rubocop:enable Lint/UnusedMethodArgument, Style/CaseEquality
|
||||
# custom -> print only the message if no backtrace is present
|
||||
return "#{msg.message}\n" if !msg.backtrace
|
||||
# otherwise combination of message and backtrace
|
||||
"#{msg.message}\n#{msg.backtrace.join("\n")}\n"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,30 @@
|
|||
# This customization removes the tagged logging functionality in favour of logging exception backtraces via the Rails.logger.
|
||||
# Zammad uses Logger::Formatter which partly provides the functionality to log exceptions if given.
|
||||
# ActiveSupport::TaggedLogging::Formatter removes this by addind the tags as a string which converts the Exception class to
|
||||
# a flat string without the backtrace and other information. It's reduced to only the exception text. This is not wanted
|
||||
# in our context.
|
||||
# ActiveSupport::TaggedLogging::Formatter addresses:
|
||||
# subdomains, request ids, and anything else to aid debugging of multi-user production applications.
|
||||
# Which is not needed for us
|
||||
#
|
||||
# @example:
|
||||
# begin
|
||||
# instance = "String :)"
|
||||
# instance.invalid_method
|
||||
# rescue => e
|
||||
# Rails.logger.error e
|
||||
# end
|
||||
# #=> undefined method `invalid_method' for "String :)":String
|
||||
# # ... backtrace ...
|
||||
# https://github.com/rails/rails/blob/89fab56597c335bb49887563b9a98386b5171574/activesupport/lib/active_support/tagged_logging.rb
|
||||
module ActiveSupport
|
||||
module TaggedLogging
|
||||
module Formatter
|
||||
# This method is invoked when a log event occurs.
|
||||
def call(severity, timestamp, progname, msg)
|
||||
# super(severity, timestamp, progname, "#{tags_text}#{msg}")
|
||||
super(severity, timestamp, progname, msg)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue