Class: Graylog2Rails::Message
- Inherits:
-
Object
- Object
- Graylog2Rails::Message
- Defined in:
- lib/graylog2-rails/message.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
The action (if any) that was called in this request.
-
#args ⇒ Object
Returns the value of attribute args.
-
#backtrace ⇒ Object
The backtrace from the given exception or hash.
-
#backtrace_filters ⇒ Object
See Configuration#backtrace_filters.
-
#cgi_data ⇒ Object
CGI variables such as HTTP_METHOD.
-
#component ⇒ Object
(also: #controller)
The component (if any) which was used in this request (usually the controller).
-
#environment_filters ⇒ Object
writeonly
Sets the attribute environment_filters.
-
#environment_name ⇒ Object
The name of the server environment (such as “production”).
-
#error_class ⇒ Object
The name of the class of error (such as RuntimeError).
-
#error_message ⇒ Object
The message from the exception, or a general description of the error.
-
#exception ⇒ Object
The exception that caused this notice, if any.
-
#hostname ⇒ Object
The host name where this error occurred (if any).
-
#parameters ⇒ Object
(also: #params)
A hash of parameters from the query string or post body.
-
#params_filters ⇒ Object
readonly
See Configuration#params_filters.
-
#project_root ⇒ Object
readonly
The path to the project that caused the error (usually Rails.root).
-
#session_data ⇒ Object
A hash of session data from the request.
-
#url ⇒ Object
The URL at which the error occurred (if any).
Instance Method Summary collapse
- #action_dispatch_params ⇒ Object
- #exception_attribute(attribute, default = nil, &block) ⇒ Object
- #find_session_data ⇒ Object
- #from_exception(attribute) ⇒ Object
-
#initialize(args) ⇒ Message
constructor
A new instance of Message.
- #message ⇒ Object
- #rack_env(method) ⇒ Object
- #rack_request ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(args) ⇒ Message
Returns a new instance of Message.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/graylog2-rails/message.rb', line 56 def initialize(args) self.args = args self.exception = args[:exception] self.url = args[:url] || rack_env(:url) self.parameters = args[:parameters] || action_dispatch_params || rack_env(:params) || {} self.component = args[:component] || args[:controller] || parameters['controller'] self.action = args[:action] || parameters['action'] self.environment_name = args[:environment_name] self.cgi_data = args[:cgi_data] || args[:rack_env] self.backtrace = self.exception.backtrace.join("\n") self.error_class = exception_attribute(:error_class) {|exception| exception.class.name } self. = exception_attribute(:error_message, 'Notification') do |exception| "#{exception.class.name}: #{exception.}" end end |
Instance Attribute Details
#action ⇒ Object
The action (if any) that was called in this request
37 38 39 |
# File 'lib/graylog2-rails/message.rb', line 37 def action @action end |
#args ⇒ Object
Returns the value of attribute args.
3 4 5 |
# File 'lib/graylog2-rails/message.rb', line 3 def args @args end |
#backtrace ⇒ Object
The backtrace from the given exception or hash.
8 9 10 |
# File 'lib/graylog2-rails/message.rb', line 8 def backtrace @backtrace end |
#backtrace_filters ⇒ Object
See Configuration#backtrace_filters
23 24 25 |
# File 'lib/graylog2-rails/message.rb', line 23 def backtrace_filters @backtrace_filters end |
#cgi_data ⇒ Object
CGI variables such as HTTP_METHOD
17 18 19 |
# File 'lib/graylog2-rails/message.rb', line 17 def cgi_data @cgi_data end |
#component ⇒ Object Also known as: controller
The component (if any) which was used in this request (usually the controller)
33 34 35 |
# File 'lib/graylog2-rails/message.rb', line 33 def component @component end |
#environment_filters=(value) ⇒ Object (writeonly)
Sets the attribute environment_filters
51 52 53 |
# File 'lib/graylog2-rails/message.rb', line 51 def environment_filters=(value) @environment_filters = value end |
#environment_name ⇒ Object
The name of the server environment (such as “production”)
14 15 16 |
# File 'lib/graylog2-rails/message.rb', line 14 def environment_name @environment_name end |
#error_class ⇒ Object
The name of the class of error (such as RuntimeError)
11 12 13 |
# File 'lib/graylog2-rails/message.rb', line 11 def error_class @error_class end |
#error_message ⇒ Object
The message from the exception, or a general description of the error
20 21 22 |
# File 'lib/graylog2-rails/message.rb', line 20 def @error_message end |
#exception ⇒ Object
The exception that caused this notice, if any
5 6 7 |
# File 'lib/graylog2-rails/message.rb', line 5 def exception @exception end |
#hostname ⇒ Object
The host name where this error occurred (if any)
49 50 51 |
# File 'lib/graylog2-rails/message.rb', line 49 def hostname @hostname end |
#parameters ⇒ Object Also known as: params
A hash of parameters from the query string or post body.
29 30 31 |
# File 'lib/graylog2-rails/message.rb', line 29 def parameters @parameters end |
#params_filters ⇒ Object (readonly)
See Configuration#params_filters
26 27 28 |
# File 'lib/graylog2-rails/message.rb', line 26 def params_filters @params_filters end |
#project_root ⇒ Object (readonly)
The path to the project that caused the error (usually Rails.root)
43 44 45 |
# File 'lib/graylog2-rails/message.rb', line 43 def project_root @project_root end |
#session_data ⇒ Object
A hash of session data from the request
40 41 42 |
# File 'lib/graylog2-rails/message.rb', line 40 def session_data @session_data end |
#url ⇒ Object
The URL at which the error occurred (if any)
46 47 48 |
# File 'lib/graylog2-rails/message.rb', line 46 def url @url end |
Instance Method Details
#action_dispatch_params ⇒ Object
82 83 84 |
# File 'lib/graylog2-rails/message.rb', line 82 def action_dispatch_params args[:rack_env]['action_dispatch.request.parameters'] if args[:rack_env] end |
#exception_attribute(attribute, default = nil, &block) ⇒ Object
92 93 94 |
# File 'lib/graylog2-rails/message.rb', line 92 def exception_attribute(attribute, default = nil, &block) (exception && from_exception(attribute, &block)) || args[attribute] || default end |
#find_session_data ⇒ Object
104 105 106 107 |
# File 'lib/graylog2-rails/message.rb', line 104 def find_session_data self.session_data = args[:session_data] || args[:session] || rack_session || {} self.session_data = session_data[:data] if session_data[:data] end |
#from_exception(attribute) ⇒ Object
96 97 98 99 100 101 102 |
# File 'lib/graylog2-rails/message.rb', line 96 def from_exception(attribute) if block_given? yield(exception) else exception.send(attribute) end end |
#message ⇒ Object
74 75 76 |
# File 'lib/graylog2-rails/message.rb', line 74 def self. end |
#rack_env(method) ⇒ Object
78 79 80 |
# File 'lib/graylog2-rails/message.rb', line 78 def rack_env(method) rack_request.send(method) if rack_request end |
#rack_request ⇒ Object
86 87 88 89 90 |
# File 'lib/graylog2-rails/message.rb', line 86 def rack_request @rack_request ||= if args[:rack_env] ::Rack::Request.new(args[:rack_env]) end end |
#to_s ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/graylog2-rails/message.rb', line 109 def to_s = [] << "=================== Git revision" << `git log --pretty=format:'%H' -n 1` << "=================== Exception Class" << self.error_class << "=================== Exception Message" << self. << "=================== URL" << self.url << "=================== Parameters" << args[:rack_env]['REQUEST_METHOD'] << self.parameters << "=================== Component" << self.component << "=================== Action" << self.action << "=================== Ruby version" << RUBY_VERSION << "=================== Rails environment" << Rails.env << "=================== User information" << args[:rack_env]['HTTP_USER_AGENT'] << args[:rack_env]['HTTP_ACCEPT_CHARSET'] << "=================== Backtrace" << self.backtrace << "=================== ARGS" << self.args .join("\n\n") end |