Class: Logman::Rails

Inherits:
Object
  • Object
show all
Defined in:
lib/logman_rails.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ Rails

Returns a new instance of Rails.



29
30
31
32
33
# File 'lib/logman_rails.rb', line 29

def initialize(app, options = {})
  @app, @options = app, options
  @options[:ignore_exceptions] ||= self.class.default_ignore_exceptions
  Logman.options = @options
end

Class Method Details

.default_ignore_exceptionsObject



21
22
23
24
25
26
27
# File 'lib/logman_rails.rb', line 21

def self.default_ignore_exceptions
  [].tap do |exceptions|
    exceptions << ActiveRecord::RecordNotFound if defined? ActiveRecord
    # exceptions << AbstractController::ActionNotFound if defined? AbstractController
    exceptions << ActionController::RoutingError if defined? ActionController
  end
end

Instance Method Details

#call(env) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/logman_rails.rb', line 35

def call(env)
@app.call(env)

rescue Exception => exception
	options = (env['exception_notifier.options'] ||= {})
	options.reverse_merge!(@options)

	raise exception if options[:endpoint].nil? || options[:token].nil?

	unless Array.wrap(options[:ignore_exceptions]).include?(exception.class)
	  # Notifier.exception_notification(env, exception).deliver
	  # env['exception_notifier.delivered'] = true
	  newlog = Log.new
	  newlog.message = exception.to_s

	  data = {}
	  data[:exception_class] = exception.class.name
	  data[:backtrace] = exception.backtrace
	  data[:params] = env["action_dispatch.request.parameters"]

	  newlog.data = data

	  Logman.send(newlog, options[:endpoint], options[:token])
	end

	raise exception
end