mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 12:42:16 +08:00
DEV: Consolidate Unicorn error backtraces when logstash is enabled.
This commit is contained in:
parent
23778f4bfd
commit
bb8f1ce8b1
|
@ -4,6 +4,7 @@
|
|||
|
||||
if (ENV["LOGSTASH_UNICORN_URI"] || "").length > 0
|
||||
require_relative '../lib/discourse_logstash_logger'
|
||||
require_relative '../lib/unicorn_logstash_patch'
|
||||
logger DiscourseLogstashLogger.logger(uri: ENV['LOGSTASH_UNICORN_URI'], type: :unicorn)
|
||||
end
|
||||
|
||||
|
|
12
lib/unicorn_logstash_patch.rb
Normal file
12
lib/unicorn_logstash_patch.rb
Normal file
|
@ -0,0 +1,12 @@
|
|||
# See https://github.com/defunkt/unicorn/commit/5f478f5a9a58f72c0a844258b8ee614bf24ea9f7
|
||||
# Unicorn originally logs backtrace line by line with `exc.backtrace.each { |line| logger.error(line) }`.
|
||||
# However, that means we get a separate logstash message for each backtrace which isn't what we want. The
|
||||
# monkey patch here overrides Unicorn's logging of error so that we log the error and backtrace in a
|
||||
# single message.
|
||||
module Unicorn
|
||||
def self.log_error(logger, prefix, exc)
|
||||
message = exc.message
|
||||
message = message.dump if /[[:cntrl:]]/ =~ message
|
||||
logger.error "#{prefix}: #{message} (#{exc.class})\n#{exc.backtrace.join("\n")}"
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user