Class: Log::Utils

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

Class Method Summary collapse

Class Method Details

.prepare_message(message, simple = false) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/log/utils.rb', line 16

def self.prepare_message(message, simple=false)
  if message.kind_of? Exception
    if simple
      return message.message
    else
      return pretty_print_exception(message)
    end
  end

  return message.to_s
end

.pretty_print_exception(exception) ⇒ Object

Raises:

  • (ArgumentError)


3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/log/utils.rb', line 3

def self.pretty_print_exception(exception)
  raise ArgumentError.new("must pass exception") if (!exception.kind_of? Exception)

  # Code taken from C:\Ruby192\lib\ruby\gems\1.9.1\gems\actionpack-3.0.3\lib\action_dispatch\middleware\show_exceptions.rb
  message = "\n#{exception.class} (#{exception.message}):\n"
  message << exception.annoted_source_code.to_s if exception.respond_to?(:annoted_source_code)
  message << "  " << (defined?(Rails) && Rails.respond_to?(:backtrace_cleaner) && exception.backtrace ?
        Rails.backtrace_cleaner.clean(exception.backtrace) :
        exception.backtrace).try(:join, "\n  ").to_s

  return message
end