Class: Graylog2Rails::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/graylog2-rails/message.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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.error_message    = exception_attribute(:error_message, 'Notification') do |exception|
    "#{exception.class.name}: #{exception.message}"
  end
end

Instance Attribute Details

#actionObject

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

#argsObject

Returns the value of attribute args.



3
4
5
# File 'lib/graylog2-rails/message.rb', line 3

def args
  @args
end

#backtraceObject

The backtrace from the given exception or hash.



8
9
10
# File 'lib/graylog2-rails/message.rb', line 8

def backtrace
  @backtrace
end

#backtrace_filtersObject

See Configuration#backtrace_filters



23
24
25
# File 'lib/graylog2-rails/message.rb', line 23

def backtrace_filters
  @backtrace_filters
end

#cgi_dataObject

CGI variables such as HTTP_METHOD



17
18
19
# File 'lib/graylog2-rails/message.rb', line 17

def cgi_data
  @cgi_data
end

#componentObject 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

Parameters:

  • value

    the value to set the attribute environment_filters to.



51
52
53
# File 'lib/graylog2-rails/message.rb', line 51

def environment_filters=(value)
  @environment_filters = value
end

#environment_nameObject

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_classObject

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_messageObject

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
  @error_message
end

#exceptionObject

The exception that caused this notice, if any



5
6
7
# File 'lib/graylog2-rails/message.rb', line 5

def exception
  @exception
end

#hostnameObject

The host name where this error occurred (if any)



49
50
51
# File 'lib/graylog2-rails/message.rb', line 49

def hostname
  @hostname
end

#parametersObject 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_filtersObject (readonly)

See Configuration#params_filters



26
27
28
# File 'lib/graylog2-rails/message.rb', line 26

def params_filters
  @params_filters
end

#project_rootObject (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_dataObject

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

#urlObject

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_paramsObject



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_dataObject



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

#messageObject



74
75
76
# File 'lib/graylog2-rails/message.rb', line 74

def message
  self.error_message
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_requestObject



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_sObject



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
  message = []
  message << "=================== Git revision"
  message << `git log --pretty=format:'%H' -n 1`
  message << "=================== Exception Class"
  message << self.error_class
  message << "=================== Exception Message"
  message << self.error_message
  message << "=================== URL"
  message << self.url
  message << "=================== Parameters"
  message << args[:rack_env]['REQUEST_METHOD']
  message << self.parameters
  message << "=================== Component"
  message << self.component
  message << "=================== Action"
  message << self.action
  message << "=================== Ruby version"
  message << RUBY_VERSION
  message << "=================== Rails environment"
  message << Rails.env
  message << "=================== User information"
  message << args[:rack_env]['HTTP_USER_AGENT']
  message << args[:rack_env]['HTTP_ACCEPT_CHARSET']
  message << "=================== Backtrace"
  message << self.backtrace
  message << "=================== ARGS"
  message << self.args
  message.join("\n\n")
end