Browse Source

exclude lambda

pagy
pvincent 11 months ago
parent
commit
d1e14fba27
  1. 4
      config/environments/development.rb
  2. 14
      lib/formatters/basic_formatter.rb

4
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

14
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

Loading…
Cancel
Save