Class: LoggedException

Inherits:
ActiveRecord::Base
  • Object
show all
Extended by:
LoggedExceptionRake::RakeExt
Defined in:
app/models/logged_exception.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from LoggedExceptionRake::RakeExt

create_from_rake_exception

Class Method Details

.class_namesObject



60
61
62
# File 'app/models/logged_exception.rb', line 60

def self.class_names
  select("DISTINCT exception_class").order(:exception_class).collect(&:exception_class)
end

.controller_actionsObject



64
65
66
# File 'app/models/logged_exception.rb', line 64

def self.controller_actions
  select("DISTINCT controller_name, action_name").order(:controller_name,:action_name).collect(&:controller_action)
end

.create_from_exception(controller, exception, data) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
# File 'app/models/logged_exception.rb', line 3

def create_from_exception(controller, exception, data)
  message = exception.message.inspect
  message << "\n* Extra Data\n\n#{data}" unless data.blank?
  e = create! \
    :exception_class => exception.class.name,
    :controller_name => controller.controller_path,
    :action_name     => controller.action_name,
    :message         => message,
    :backtrace       => exception.backtrace,
    :request         => controller.request
end

.host_nameObject



15
16
17
# File 'app/models/logged_exception.rb', line 15

def host_name
  `hostname -s`.chomp
end

Instance Method Details

#backtrace=(trace) ⇒ Object



32
33
34
35
# File 'app/models/logged_exception.rb', line 32

def backtrace=(trace)
  trace = sanitize_backtrace(trace) * "\n" unless trace.is_a?(String)
  write_attribute :backtrace, trace
end

#controller_actionObject



56
57
58
# File 'app/models/logged_exception.rb', line 56

def controller_action
  @controller_action ||= "#{controller_name.camelcase}/#{action_name}"
end

#nameObject



28
29
30
# File 'app/models/logged_exception.rb', line 28

def name
  "#{self.exception_class} in #{self.controller_action}"
end

#request=(request) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/models/logged_exception.rb', line 37

def request=(request)
  if request.is_a?(String)
    write_attribute :request, request
  else
    max = request.env.keys.max { |a,b| a.length <=> b.length }
    env = request.env.keys.sort.inject [] do |env, key|
      env << '* ' + ("%-*s: %s" % [max.length, key, request.env[key].to_s.strip])
    end
    write_attribute(:environment, (env << "* Process: #{$$}" << "* Server : #{self.class.host_name}") * "\n")
    
    write_attribute(:request, [
        "* URL:#{" #{request.method.to_s.upcase}" unless request.get?} #{request.protocol}#{request.env["HTTP_HOST"]}#{request.fullpath}",
        "* Format: #{request.format.to_s}",
        "* Parameters: #{request.parameters.inspect}",
        "* Rails Root: #{rails_root}"
      ] * "\n")
  end
end