Module: CrashLog::Logging::ClassMethods

Included in:
CrashLog
Defined in:
lib/crash_log/logging.rb

Instance Method Summary collapse

Instance Method Details

#color_for_level(level) ⇒ Object



48
49
50
51
52
53
54
55
56
57
# File 'lib/crash_log/logging.rb', line 48

def color_for_level(level)
  case level.to_sym
  when :fatel, :error, :warn
    :red
  when :debug
    :cyan
  else
    :green
  end
end

#colorize(color, text) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/crash_log/logging.rb', line 34

def colorize(color, text)
  if colorize?
    "\e[#{ANSI[color]}m#{text}\e[0m"
  else
    text
  end
end

#colorize?Boolean

Returns:

  • (Boolean)


42
43
44
45
46
# File 'lib/crash_log/logging.rb', line 42

def colorize?
  CrashLog.configuration.colorize.eql?(true)
rescue
  false
end

#log_exception(exception) ⇒ Object



59
60
61
62
63
64
65
66
67
# File 'lib/crash_log/logging.rb', line 59

def log_exception(exception)
  logger.error("#{exception.class.name}: #{exception.message}")
  exception.backtrace.each { |line| logger.error(line) } if exception.backtrace
rescue Exception => e
  puts '--- FATAL ---'
  puts 'an exception occured while logging an exception'
  puts e.message, e.backtrace
  puts exception.message, exception.backtrace
end

#loggerObject



17
18
19
# File 'lib/crash_log/logging.rb', line 17

def logger
  CrashLog.logger
end

#prefix(string, color = :green) ⇒ Object



30
31
32
# File 'lib/crash_log/logging.rb', line 30

def prefix(string, color = :green)
  [colorize(:yellow, CrashLog::LOG_PREFIX), colorize(color, string)].join(' ')
end