class Lorekeeper::SimpleLogger

Simple logger provides a logger which outputs messages in a colorized simple text format.

Constants

COLOR_DEFAULT

From misc.flogisoft.com/bash/tip_colors_and_formatting 39: default for the theme 33: yellow 31: red 37: light gray

COLOR_LIGHT_GRAY
COLOR_RED
COLOR_YELLOW
SEVERITY_TO_COLOR_MAP

Public Instance Methods

exception(exception, custom_message = nil, custom_data = nil, level = :error) click to toggle source
# File lib/lorekeeper/simple_logger.rb, line 46
def exception(exception, custom_message = nil, custom_data = nil, level = :error)
  log_level = METHOD_SEVERITY_MAP[level] || ERROR

  if exception.is_a?(Exception)
    backtrace = exception.backtrace || []
    message = custom_message || exception.message
    log_data(log_level, "#{exception.class}: #{exception.message}; #{message}, data: #{backtrace.join("\n")}")
  else
    log_data(METHOD_SEVERITY_MAP[:warn], 'Logger exception called without exception class.')
    error_with_data("#{exception.class}: #{exception.inspect} #{custom_message}", custom_data)
  end
end
inspect() click to toggle source
# File lib/lorekeeper/simple_logger.rb, line 34
def inspect
  "Lorekeeper Simple logger. IO: #{@file.inspect}"
end
log_data(severity, message) click to toggle source

e[colorm sets a color e[0m resets all properties

# File lib/lorekeeper/simple_logger.rb, line 29
def log_data(severity, message)
  color = SEVERITY_TO_COLOR_MAP[severity]
  @iodevice.write("\e[#{color}m#{message}\e[0m\n")
end