From 20fa8a5f75c4b766cab546e2529713ebb4d63cbf Mon Sep 17 00:00:00 2001 From: pvincent Date: Fri, 5 Jan 2024 12:41:04 +0400 Subject: [PATCH] color fatal --- lib/formatters/basic_formatter.rb | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/formatters/basic_formatter.rb b/lib/formatters/basic_formatter.rb index f4de5b5..028964e 100644 --- a/lib/formatters/basic_formatter.rb +++ b/lib/formatters/basic_formatter.rb @@ -2,6 +2,7 @@ class BasicFormatter < SemanticLogger::Formatters::Color ANSI_REVERSED_WARNING = "\e[0;30;43m".freeze ANSI_REVERSED_ERROR = "\e[1;30;41m".freeze + ANSI_REVERSED_FATAL = "\e[1;30;45m".freeze ANSI_GRAY = "\e[90m".freeze def initialize @@ -9,24 +10,28 @@ class BasicFormatter < SemanticLogger::Formatters::Color color_map: ColorMap.new( debug: ANSI_GRAY, info: SemanticLogger::AnsiColors::GREEN, - warn: SemanticLogger::AnsiColors::YELLOW + warn: SemanticLogger::AnsiColors::YELLOW, + fatal: SemanticLogger::AnsiColors::MAGENTA )) end def message return unless log.message + msg = log.message prefix = "#{color}--#{color_map.clear}" case log.level when :info - "#{prefix} #{SemanticLogger::AnsiColors::WHITE}#{log.message}#{color_map.clear}" + "#{prefix} #{SemanticLogger::AnsiColors::WHITE}#{msg}#{color_map.clear}" when :warn - "#{prefix} #{ANSI_REVERSED_WARNING}#{log.message}#{color_map.clear}" - when :error, :fatal - "#{prefix} #{ANSI_REVERSED_ERROR}#{log.message}#{color_map.clear}" + "#{prefix} #{ANSI_REVERSED_WARNING}#{msg}#{color_map.clear}" + when :error + "#{prefix} #{ANSI_REVERSED_ERROR}#{msg}#{color_map.clear}" + when :fatal + "#{prefix} #{ANSI_REVERSED_FATAL}#{msg}#{color_map.clear}" else - "#{prefix} #{color}#{log.message}#{color_map.clear}" + "#{prefix} #{color}#{msg}#{color_map.clear}" end end