From 351990839ee6bb657032aa3eae0e9a606dc45329 Mon Sep 17 00:00:00 2001 From: pvincent Date: Fri, 5 Jan 2024 22:26:26 +0400 Subject: [PATCH] logger.info hidden level --- app/controllers/scores_controller.rb | 2 +- lib/formatters/basic_formatter.rb | 41 ++++++++++------------------ 2 files changed, 15 insertions(+), 28 deletions(-) diff --git a/app/controllers/scores_controller.rb b/app/controllers/scores_controller.rb index f5d58b7..3d97497 100644 --- a/app/controllers/scores_controller.rb +++ b/app/controllers/scores_controller.rb @@ -10,7 +10,7 @@ class ScoresController < ApplicationController logger.error 'this is an error' logger.debug 'this is a debug message' logger.fatal 'FATAL' - logger.info @scores + logger.info @scores.inspect end # GET /scores/1 diff --git a/lib/formatters/basic_formatter.rb b/lib/formatters/basic_formatter.rb index 32ed589..16ce238 100644 --- a/lib/formatters/basic_formatter.rb +++ b/lib/formatters/basic_formatter.rb @@ -1,51 +1,38 @@ # My Custom colorized formatter 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;41m".freeze + NAME_MAX_SIZE = 25 + ANSI_DEBUG = "\e[90m".freeze ANSI_INFO = SemanticLogger::AnsiColors::GREEN ANSI_WARN = SemanticLogger::AnsiColors::YELLOW ANSI_ERROR = SemanticLogger::AnsiColors::RED ANSI_FATAL = SemanticLogger::AnsiColors::MAGENTA + ANSI_NEUTRAL_INFO = SemanticLogger::AnsiColors::WHITE + ANSI_REVERSED_WARNING = "\e[0;30;43m".freeze + ANSI_REVERSED_ERROR = "\e[1;30;41m".freeze + ANSI_REVERSED_FATAL = "\e[1;30;41m".freeze def initialize super(time_format: nil, - color_map: ColorMap.new( - debug: ANSI_DEBUG, - info: ANSI_INFO, - warn: ANSI_WARN, - fatal: ANSI_ERROR - )) + color_map: ColorMap.new(debug: ANSI_DEBUG, info: ANSI_INFO, warn: ANSI_WARN, error: ANSI_ERROR, + fatal: ANSI_ERROR)) + @content_color_map = ColorMap.new(debug: ANSI_DEBUG, info: ANSI_NEUTRAL_INFO, warn: ANSI_REVERSED_WARNING, + error: ANSI_REVERSED_ERROR, fatal: ANSI_REVERSED_FATAL) end def message return unless log.message - msg = log.message - prefix = "#{color} #{color_map.clear}" - - case log.level - when :info - "#{prefix}#{SemanticLogger::AnsiColors::WHITE}#{msg}#{color_map.clear}" - when :warn - "#{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}#{msg}#{color_map.clear}" - end + " #{@content_color_map[log.level]}#{log.message}#{color_map.clear}" end def level - "#{color}╣#{log.level.to_s.chr.upcase}╠#{color_map.clear}" + level = log.level == :info ? ' ' : log.level.to_s.chr.upcase + "#{color}╣#{level}╠#{color_map.clear}" end def name - # "#{color}#{log.name.ljust(20)}#{color_map.clear}" - "#{ANSI_DEBUG}#{log.name.rjust(20)}#{color_map.clear}" + "#{ANSI_DEBUG}#{log.name.truncate(NAME_MAX_SIZE).center(NAME_MAX_SIZE)}#{color_map.clear}" end def process_info