Class: Lorekeeper::SimpleLogger

Inherits:
FastLogger show all
Defined in:
lib/lorekeeper/simple_logger.rb

Overview

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

Constant Summary collapse

COLOR_DEFAULT =

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

'39'
COLOR_YELLOW =
'33'
COLOR_RED =
'31'
COLOR_LIGHT_GRAY =
'37'
SEVERITY_TO_COLOR_MAP =
{
  DEBUG => COLOR_DEFAULT,
  INFO => COLOR_DEFAULT,
  WARN => COLOR_YELLOW,
  ERROR => COLOR_RED,
  FATAL => COLOR_RED,
  UNKNOWN => COLOR_LIGHT_GRAY
}.freeze

Constants inherited from FastLogger

FastLogger::LOGGING_METHODS, FastLogger::METHOD_SEVERITY_MAP, FastLogger::SEVERITY_NAMES_MAP

Instance Attribute Summary

Attributes inherited from FastLogger

#formatter, #level

Instance Method Summary collapse

Methods inherited from FastLogger

#add, #debug?, #error?, #fatal?, #info?, #initialize, #silence, #silence_logger, #warn?

Constructor Details

This class inherits a constructor from Lorekeeper::FastLogger

Instance Method Details

#exception(exception, custom_message = nil, custom_data = nil, level = :error) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
# 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

#inspectObject



34
35
36
# File 'lib/lorekeeper/simple_logger.rb', line 34

def inspect
  "Lorekeeper Simple logger. IO: #{@file.inspect}"
end

#log_data(severity, message) ⇒ Object

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



29
30
31
32
# 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