Class: ExceptionNotifier::DbNotifier
Instance Attribute Summary
Attributes inherited from BaseNotifier
#base_options
Instance Method Summary
collapse
#_post_callback, #_pre_callback, #send_notice
Constructor Details
#initialize(opts = {}) ⇒ DbNotifier
5
6
7
|
# File 'lib/exception_notifier/db_notifier.rb', line 5
def initialize(opts = {})
super(opts)
end
|
Instance Method Details
#call(exception, opts = {}) ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/exception_notifier/db_notifier.rb', line 9
def call(exception, opts = {})
return unless ExceptionTrack.config.enabled_env?(Rails.env)
title = exception.message || "None"
messages = []
ActiveSupport::Notifications.instrument("track.exception_track", title: title) do
messages << (opts[:env])
messages << ""
messages << "--------------------------------------------------"
messages << ""
messages << exception.inspect
unless exception.backtrace.blank?
messages << "\n"
messages << exception.backtrace
end
Rails.logger.silence do
ExceptionTrack::Log.create(title: title[0, 200], body: messages.join("\n"))
end
end
rescue => e
errs = []
errs << "-- [ExceptionTrack] create error ---------------------------"
errs << e.message.indent(2)
errs << ""
errs << "-- Exception detail ----------------------------------------"
errs << title.indent(2)
errs << ""
errs << messages.join("\n").indent(2)
Rails.logger.error errs.join("\n")
end
|
#filter_parameters(env) ⇒ Object
64
65
66
67
68
69
70
71
|
# File 'lib/exception_notifier/db_notifier.rb', line 64
def filter_parameters(env)
parameters = env["action_dispatch.request.parameters"] || {}
parameter_filter = ActiveSupport::ParameterFilter.new(env["action_dispatch.parameter_filter"] || [])
parameter_filter.filter(parameters)
rescue => e
Rails.logger.error "filter_parameters error: #{e.inspect}"
parameters
end
|
Log Request headers from Rack env
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/exception_notifier/db_notifier.rb', line 44
def (env)
return "" if env.blank?
parameters = filter_parameters(env)
= []
<< "Method: #{env["REQUEST_METHOD"]}"
<< "URL: #{env["REQUEST_URI"]}"
<< "Parameters:\n#{pretty_hash(parameters.except(:controller, :action), 13)}" if env["REQUEST_METHOD"].downcase != "get"
<< "Controller: #{parameters["controller"]}##{parameters["action"]}"
<< "RequestId: #{env["action_dispatch.request_id"]}"
<< "User-Agent: #{env["HTTP_USER_AGENT"]}"
<< "Remote IP: #{env["REMOTE_ADDR"]}"
<< "Language: #{env["HTTP_ACCEPT_LANGUAGE"]}"
<< "Server: #{Socket.gethostname}"
<< "Process: #{$PROCESS_ID}"
.join("\n")
end
|
#pretty_hash(params, indent = 0) ⇒ Object
73
74
75
76
|
# File 'lib/exception_notifier/db_notifier.rb', line 73
def pretty_hash(params, indent = 0)
json = JSON.pretty_generate(params)
json.indent(indent)
end
|