Module: ExceptionLogger::ExceptionLoggable

Defined in:
lib/exception_logger/exception_loggable.rb

Overview

Copyright © 2005 Jamis Buck

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(target) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/exception_logger/exception_loggable.rb', line 26

def self.included(target)
  target.class_attribute :local_addresses
  target.class_attribute :exception_data
  
  target.extend(ClassMethods)

  #ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.merge!({
  #    :exc_full => "%A, %b %d, %Y at %l:%M %p",
  #    :exc_date => "%b %d, %Y",
  #    :exc_time => "%l:%M %p"
  #  })
end

Instance Method Details

#local_request?Boolean

Returns:

  • (Boolean)


63
64
65
66
# File 'lib/exception_logger/exception_loggable.rb', line 63

def local_request?
  remote = IPAddr.new(request.remote_ip)
  !self.class.local_addresses.detect { |addr| addr.include?(remote) }.nil?
end

#log_exception(exception) ⇒ Object



80
81
82
83
84
85
86
87
88
89
# File 'lib/exception_logger/exception_loggable.rb', line 80

def log_exception(exception)
  deliverer = self.class.exception_data
  data = case deliverer
  when nil    then {}
  when Symbol then send(deliverer)
  when Proc   then deliverer.call(self)
  end

  LoggedException.create_from_exception(self, exception, data)
end

#log_exception_handler(exception) ⇒ Object

we log the exception and raise it again, for the normal handling.



69
70
71
72
# File 'lib/exception_logger/exception_loggable.rb', line 69

def log_exception_handler(exception)
  log_exception(exception)
  raise exception
end

#rescue_action(exception) ⇒ Object



74
75
76
77
78
# File 'lib/exception_logger/exception_loggable.rb', line 74

def rescue_action(exception)
  status = response_code_for_rescue(exception)
  log_exception(exception) if status != :not_found
  super
end