Class: RailsGraylogger::Message
- Inherits:
-
Object
- Object
- RailsGraylogger::Message
- Defined in:
- lib/rails-graylogger/message.rb
Constant Summary collapse
- FIELD_KEY_REGEXP =
/^[\w\.\-]*$/
Instance Attribute Summary collapse
-
#extra_fields ⇒ Object
Returns the value of attribute extra_fields.
-
#full_message ⇒ Object
Returns the value of attribute full_message.
-
#level ⇒ Object
Returns the value of attribute level.
-
#short_message ⇒ Object
Returns the value of attribute short_message.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Message
constructor
A new instance of Message.
- #process_event_payload(payload) ⇒ Object
- #process_extra_fields(payload) ⇒ Object
- #tags=(tags) ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Message
Returns a new instance of Message.
7 8 9 10 11 12 |
# File 'lib/rails-graylogger/message.rb', line 7 def initialize(opts = {}) @level = opts[:level] || GELF::Levels::INFO @short_message = opts[:short_message] || "" @full_message = opts[:full_message] || "" @extra_fields = {} end |
Instance Attribute Details
#extra_fields ⇒ Object
Returns the value of attribute extra_fields.
5 6 7 |
# File 'lib/rails-graylogger/message.rb', line 5 def extra_fields @extra_fields end |
#full_message ⇒ Object
Returns the value of attribute full_message.
5 6 7 |
# File 'lib/rails-graylogger/message.rb', line 5 def @full_message end |
#level ⇒ Object
Returns the value of attribute level.
5 6 7 |
# File 'lib/rails-graylogger/message.rb', line 5 def level @level end |
#short_message ⇒ Object
Returns the value of attribute short_message.
5 6 7 |
# File 'lib/rails-graylogger/message.rb', line 5 def @short_message end |
Class Method Details
.from_event_payload(payload) ⇒ Object
15 16 17 18 19 |
# File 'lib/rails-graylogger/message.rb', line 15 def from_event_payload(payload) = self.new .process_event_payload(payload) end |
Instance Method Details
#process_event_payload(payload) ⇒ Object
22 23 24 25 26 |
# File 'lib/rails-graylogger/message.rb', line 22 def process_event_payload(payload) self.level = level_from_status(payload[:status]) self. = "#{payload[:controller]}##{payload[:action]} #{payload[:method]} \"#{payload[:path]}\" from #{payload[:ipaddress]}" process_extra_fields(payload) end |
#process_extra_fields(payload) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/rails-graylogger/message.rb', line 42 def process_extra_fields(payload) process_exception_data(payload.delete(:exception)) payload.each do |key, value| @extra_fields["_#{key}"] = formatted_value(value) if valid_key?(key) end end |
#tags=(tags) ⇒ Object
28 29 30 31 |
# File 'lib/rails-graylogger/message.rb', line 28 def () raise ArgumentError.new("Not an array: #{.inspect}") unless .is_a?(Array) self.extra_fields[:_tags] = .join(" ") end |
#to_hash ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/rails-graylogger/message.rb', line 33 def to_hash { level: level, short_message: }.tap do |hash| hash[:full_message] = + "\n" + unless .blank? end.merge(extra_fields) end |