newrelic: refactor error logging.
* Factor out New Relic logging to DanbooruLogger class. * Log all exceptions to New Relic, not just statement timeouts.
This commit is contained in:
12
app/logical/danbooru_logger.rb
Normal file
12
app/logical/danbooru_logger.rb
Normal file
@@ -0,0 +1,12 @@
|
||||
class DanbooruLogger
|
||||
def self.log(exception, expected: false, **params)
|
||||
if !expected
|
||||
backtrace = Rails.backtrace_cleaner.clean(exception.backtrace).join("\n")
|
||||
Rails.logger.error("#{exception.class}: #{exception.message}\n#{backtrace}")
|
||||
end
|
||||
|
||||
if defined?(::NewRelic)
|
||||
::NewRelic::Agent.notice_error(exception, expected: expected, custom_params: params)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -41,13 +41,7 @@ module Maintenance
|
||||
end
|
||||
|
||||
def rescue_exception(exception)
|
||||
backtrace = Rails.backtrace_cleaner.clean(exception.backtrace).join("\n")
|
||||
Rails.logger.error("#{exception.class}: #{exception.message}\n#{backtrace}")
|
||||
|
||||
if defined?(NewRelic::Agent)
|
||||
NewRelic::Agent.notice_error(exception, custom_params: { backtrace: backtrace })
|
||||
end
|
||||
|
||||
DanbooruLogger.log(exception)
|
||||
raise exception
|
||||
end
|
||||
end
|
||||
|
||||
@@ -72,7 +72,7 @@ module Moderator
|
||||
user.update(blacklisted_tags: repl.join("\n"))
|
||||
end
|
||||
rescue Exception => e
|
||||
NewRelic::Agent.notice_error(e)
|
||||
DanbooruLogger.log(e)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -56,10 +56,7 @@ class PopularSearchService
|
||||
data
|
||||
|
||||
rescue => e
|
||||
Rails.logger.error(e.to_s)
|
||||
if defined?(NewRelic)
|
||||
NewRelic::Agent.notice_error(e)
|
||||
end
|
||||
DanbooruLogger.log(e)
|
||||
return []
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user