Class: Loggerator::Railtie::LogSubscriber

Inherits:
ActiveSupport::LogSubscriber
  • Object
show all
Includes:
Loggerator
Defined in:
lib/loggerator/railtie/log_subscriber.rb

Constant Summary collapse

FIELDS =
[:method, :path, :format, :controller, :action, :status,
:error, :duration, :view, :db, :location].freeze

Instance Method Summary collapse

Methods included from Loggerator

config, config=, included, #log, log?, #log_context, #log_error, #log_error_off, #log_error_on, #log_off, #log_on, #m, turn_log

Instance Method Details

#process_action(event) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/loggerator/railtie/log_subscriber.rb', line 15

def process_action(event)
  exception = event.payload[:exception]
  if exception.present?
    # In Rails 3.2.9 event.payload[:exception] was changed from an
    # Exception object to an Array containing the e.class.name and
    # e.message. Adding handling for this case here.
    if exception.is_a?(Array)
      exception_class_name, exception_message = exception
      exception = exception_class_name.constantize.new(exception_message)
    end

    self.log_error(exception, status: 500)
  else
    self.log(extract_request_data_from_event(event))
  end
end

#redirect_to(event) ⇒ Object



32
33
34
# File 'lib/loggerator/railtie/log_subscriber.rb', line 32

def redirect_to(event)
  Thread.current[:scrolls_rails_location] = event.payload[:location]
end