You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
require_relative 'ansi_wrapper' require_relative 'ansi_colors'
require 'io/console' require 'amazing_print' require 'json'
class AnsiFormatter < SemanticLogger::Formatters::Color include AnsiColors
ANSI_DEBUG = BG_BLACK + TEXT_GRAY_500 ANSI_INFO = BG_BLACK + TEXT_GRAY_200 ANSI_WARN = BG_YELLOW + TEXT_BLACK ANSI_ERROR = BG_RED + TEXT_BLACK ANSI_FATAL = DARK_BG_RED + TEXT_BLACK
def initialize super(color_map: ColorMap.new( debug: ANSI_DEBUG, info: ANSI_INFO, warn: ANSI_WARN, error: ANSI_ERROR, fatal: ANSI_FATAL )) end
def message return unless log.message
colorize(log.message, color_map[log.level]) end
def call(log, logger) self.log = log self.logger = logger self.color = color_map[log.level] wrap_level(level, message, payload, exception) end
private
def colorize(text, color) "#{color}#{text}#{color_map.clear}" end
def wrap_level(level, *items) prefix = " #{colorize('>', color)} " continuation = " #{colorize('#', color)} " items.map do |item| AnsiWrapper.wrap(item, 100, prefix, continuation) end.compact.join("\n") # FIXME: previously was: join(' ') end end
|