diff --git a/config/initializers/backtrace_silencers.rb b/config/initializers/backtrace_silencers.rb index 9aa383559..e7ff42aa1 100644 --- a/config/initializers/backtrace_silencers.rb +++ b/config/initializers/backtrace_silencers.rb @@ -3,7 +3,11 @@ # Be sure to restart your server when you modify this file. # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. -# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } +# Rails.backtrace_cleaner.add_silencer { |line| %r{puma|rubygems}.match?(line) } -# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. +# You can add backtrace filters to modify lines of data. +# Rails.backtrace_cleaner.add_filter { |line| line.gsub(Rails.root.to_s, '') } + +# You can also remove all the silencers and filters if you're trying to debug a problem that might stem from framework code. # Rails.backtrace_cleaner.remove_silencers! +# Rails.backtrace_cleaner.remove_filters! diff --git a/lib/core_ext/logger/formatter.rb b/lib/core_ext/logger/formatter.rb index 9d10abb8e..4225a9faf 100644 --- a/lib/core_ext/logger/formatter.rb +++ b/lib/core_ext/logger/formatter.rb @@ -1,6 +1,7 @@ # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ # This customization adds the id of the current Thread to all log lines. +# The #msg2str method will be extended, so that the "Rails.bracktrace_cleaner" can be used to clean the exceptions. # It was introduced to make it more easy to follow the execution of tasks in the log in threaded processes. # # before: @@ -18,5 +19,19 @@ class Logger def call(severity, time, progname, msg) format(FORMAT_WITH_THREAD_ID, severity[0..0], format_datetime(time), Process.pid, Thread.current.object_id, severity, progname, msg2str(msg)) end + + private + + def msg2str(msg) + case msg + when ::String + msg + when ::Exception + # "#{ msg.message } (#{ msg.class })\n#{ msg.backtrace.join("\n") if msg.backtrace }" + "#{msg.message} (#{msg.class})\n#{Rails.backtrace_cleaner.clean(msg.backtrace).join("\n") if msg.backtrace}" + else + msg.inspect + end + end end end