Class: RailsGraylogger::LogSubscriber
- Inherits:
-
ActiveSupport::LogSubscriber
- Object
- ActiveSupport::LogSubscriber
- RailsGraylogger::LogSubscriber
- Defined in:
- lib/rails-graylogger/log_subscriber.rb
Instance Method Summary collapse
- #buffered_messages ⇒ Object
- #process_action(event) ⇒ Object
- #status_from_exception(exception) ⇒ Object
Instance Method Details
#buffered_messages ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/rails-graylogger/log_subscriber.rb', line 21 def unless RailsGraylogger::Logger.request_buffer.blank? RailsGraylogger::Logger.request_buffer.map{ |item| item[:short_message] unless item[:short_message].blank? }.compact.join("\n") else [] end end |
#process_action(event) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/rails-graylogger/log_subscriber.rb', line 4 def process_action(event) payload = event.payload payload[:path] = URI(payload[:path]).path if payload[:path] payload[:ipaddress] = RequestStore.store[:ipaddress] payload[:x_forwarded_for] = RequestStore.store[:x_forwarded_for] payload[:duration] = event.duration.round payload[:status] = status_from_exception(payload[:exception]) unless payload[:status].present? = RailsGraylogger::Message.from_event_payload(payload) . = RailsGraylogger::Logger. . = RailsGraylogger::Notifier.notify!(.to_hash) rescue => ex Rails.logger.error "Exception in RailsGraylogger: #{ex.class}: #{ex.}" end |
#status_from_exception(exception) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/rails-graylogger/log_subscriber.rb', line 29 def status_from_exception(exception) if exception.present? exception_class_name = exception.first ActionDispatch::ExceptionWrapper.status_code_for_exception(exception_class_name) end end |