Browse Source

prefix_internal

pagy
pvincent 10 months ago
parent
commit
317b9dca08
  1. 9
      app/controllers/scores_controller.rb
  2. 15
      lib/formatters/basic_formatter.rb

9
app/controllers/scores_controller.rb

@ -4,13 +4,14 @@ class ScoresController < ApplicationController
# GET /scores
def index
# TODO: my todo list is beginning
@scores = Score.all
logger.debug 'this is a debug message'
logger.debug({ one: 1, two: 2 })
logger.info 'this is a normal message'
# logger.info({ one: 1, two: 2 })
# logger.info 'this is an information', { four: 4, five: 5 }
# logger.debug BigDecimal('0.0003')
# logger.debug 'scores are', @scores
logger.warn 'scores are', @scores
logger.error 'this is an error message'
logger.info 'end of normal message'
# logger.debug @scores
# sleep 0.5
end

15
lib/formatters/basic_formatter.rb

@ -8,6 +8,9 @@ class BasicFormatter < SemanticLogger::Formatters::Color # rubocop:disable Metri
NAME_MAX_SIZE = 25
TERMINAL_PREFIX = ENV['TERMINAL_PREFIX'].to_i || 0
CONTENT_PREFIX = ' '.freeze
PREFIX_RAILS_INTERNAL = '➟ '.freeze
PREFIX_ACTION_INTERNAL = '↪ '.freeze
PREFIX_BUG_INTERNAL = '↪ '.freeze
RENDERED_VIEW_DURATION = 100
COMPLETED_DURATION = RENDERED_VIEW_DURATION * 5
@ -120,7 +123,7 @@ class BasicFormatter < SemanticLogger::Formatters::Color # rubocop:disable Metri
log = transform_action_view_base(log)
elsif log.name == 'Rails' && log.message
log.message = transform_rails_message(log.message.rstrip)
log.level = :debug if log.message.lstrip =~ /^Processing/ || log.message.lstrip =~ /^Parameters/
log.level = :debug if log.message =~ /^#{PREFIX_RAILS_INTERNAL}(Processing|Parameters)/
end
log
end
@ -132,7 +135,9 @@ class BasicFormatter < SemanticLogger::Formatters::Color # rubocop:disable Metri
when /^Started/
two_captures_last_as_bold(message, /(^Started \w* )"(.*?)"/)
when /^Processing/
" #{two_captures_last_as_bold(message, /(^Processing by \w*#\w* as )(.*)/)}"
"#{PREFIX_RAILS_INTERNAL}#{two_captures_last_as_bold(message, /(^Processing by \w*#\w* as )(.*)/)}"
when / Parameters/
"#{PREFIX_RAILS_INTERNAL}#{message.lstrip}"
else
message
end
@ -155,7 +160,7 @@ class BasicFormatter < SemanticLogger::Formatters::Color # rubocop:disable Metri
log.level, message = transform_log_debug_lstrip(log)
message = transform_rendered_message_with_filename(message)
message = transform_duration_strip(message)
log.message = message
log.message = "#{PREFIX_ACTION_INTERNAL}#{message}"
log
end
@ -169,7 +174,7 @@ class BasicFormatter < SemanticLogger::Formatters::Color # rubocop:disable Metri
def transform_rendered_message_with_filename(message)
md = message.match(/^Rendered( layout| collection of|) (.*?\.erb)/)
filename = "app/views/#{md.match(2)}"
log.message = " Rendered#{md.match(1)} #{filename}#{md.post_match}"
log.message = "Rendered#{md.match(1)} #{filename}#{md.post_match}"
end
def transform_log_debug_lstrip(log)
@ -202,7 +207,7 @@ class BasicFormatter < SemanticLogger::Formatters::Color # rubocop:disable Metri
def backtrace(stack)
return "\n" unless stack.count.positive?
"\n#{before_message} #{ANSI_ERROR}#{stack.join("\n#{before_message} #{ANSI_ERROR}")}#{color_map.clear}\n"
"\n#{before_message}#{ANSI_ERROR}#{PREFIX_BUG_INTERNAL}#{stack.join("\n#{before_message}#{ANSI_ERROR}#{PREFIX_BUG_INTERNAL}")}#{color_map.clear}\n"
end
def color_content

Loading…
Cancel
Save