From d1e14fba278c51331e3bbb198bd428f7b9ed45a9 Mon Sep 17 00:00:00 2001 From: pvincent Date: Sat, 6 Jan 2024 00:50:58 +0400 Subject: [PATCH] exclude lambda --- config/environments/development.rb | 4 +++- lib/formatters/basic_formatter.rb | 14 +++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/config/environments/development.rb b/config/environments/development.rb index 9de2b06..f44c0e9 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -81,5 +81,7 @@ Rails.application.configure do # rubocop:disable Metrics/BlockLength config.rails_semantic_logger.rendered = true config.rails_semantic_logger.add_file_appender = false require Rails.root.join('lib', 'formatters', 'basic_formatter') - config.semantic_logger.add_appender(io: $stdout, formatter: BasicFormatter.new) + config.semantic_logger.add_appender(io: $stdout, + formatter: BasicFormatter.new, + filter: BasicFormatter::EXCLUDE_LAMBDA) end diff --git a/lib/formatters/basic_formatter.rb b/lib/formatters/basic_formatter.rb index 511d4f8..9f4accf 100644 --- a/lib/formatters/basic_formatter.rb +++ b/lib/formatters/basic_formatter.rb @@ -6,8 +6,7 @@ class BasicFormatter < SemanticLogger::Formatters::Color 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_ERROR = "\e[91m".freeze ANSI_NEUTRAL_INFO = SemanticLogger::AnsiColors::WHITE ANSI_REVERSED_WARNING = "\e[0;30;43m".freeze ANSI_REVERSED_ERROR = "\e[1;30;41m".freeze @@ -21,6 +20,16 @@ class BasicFormatter < SemanticLogger::Formatters::Color fatal: ANSI_REVERSED_FATAL ) + EXCLUDE_LAMBDA = lambda { |log| + if log.name == 'ActionView::Base' + !log.message.starts_with?(' Rendering') + elsif log.name == 'Rails' && !log.message.nil? + log.message.exclude?('Started GET "/rails/live/reload') + else + true + end + } + def initialize super(color_map: ColorMap.new( debug: ANSI_DEBUG, @@ -65,7 +74,6 @@ class BasicFormatter < SemanticLogger::Formatters::Color self.color = color_map[log.level] self.log = log self.logger = logger - [name, level, tags, named_tags, duration, message, payload, exception].compact.join(' ') end