Browse Source

prefix_internal

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

9
app/controllers/scores_controller.rb

@ -4,13 +4,14 @@ class ScoresController < ApplicationController
# GET /scores # GET /scores
def index def index
# TODO: my todo list is beginning
@scores = Score.all @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.info 'this is an information', { four: 4, five: 5 }
# logger.debug BigDecimal('0.0003') # 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 # logger.debug @scores
# sleep 0.5 # sleep 0.5
end end

13
lib/formatters/basic_formatter.rb

@ -8,6 +8,9 @@ class BasicFormatter < SemanticLogger::Formatters::Color # rubocop:disable Metri
NAME_MAX_SIZE = 25 NAME_MAX_SIZE = 25
TERMINAL_PREFIX = ENV['TERMINAL_PREFIX'].to_i || 0 TERMINAL_PREFIX = ENV['TERMINAL_PREFIX'].to_i || 0
CONTENT_PREFIX = ' '.freeze CONTENT_PREFIX = ' '.freeze
PREFIX_RAILS_INTERNAL = '➟ '.freeze
PREFIX_ACTION_INTERNAL = '↪ '.freeze
PREFIX_BUG_INTERNAL = '↪ '.freeze
RENDERED_VIEW_DURATION = 100 RENDERED_VIEW_DURATION = 100
COMPLETED_DURATION = RENDERED_VIEW_DURATION * 5 COMPLETED_DURATION = RENDERED_VIEW_DURATION * 5
@ -120,7 +123,7 @@ class BasicFormatter < SemanticLogger::Formatters::Color # rubocop:disable Metri
log = transform_action_view_base(log) log = transform_action_view_base(log)
elsif log.name == 'Rails' && log.message elsif log.name == 'Rails' && log.message
log.message = transform_rails_message(log.message.rstrip) 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 end
log log
end end
@ -132,7 +135,9 @@ class BasicFormatter < SemanticLogger::Formatters::Color # rubocop:disable Metri
when /^Started/ when /^Started/
two_captures_last_as_bold(message, /(^Started \w* )"(.*?)"/) two_captures_last_as_bold(message, /(^Started \w* )"(.*?)"/)
when /^Processing/ 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 else
message message
end end
@ -155,7 +160,7 @@ class BasicFormatter < SemanticLogger::Formatters::Color # rubocop:disable Metri
log.level, message = transform_log_debug_lstrip(log) log.level, message = transform_log_debug_lstrip(log)
message = transform_rendered_message_with_filename(message) message = transform_rendered_message_with_filename(message)
message = transform_duration_strip(message) message = transform_duration_strip(message)
log.message = message
log.message = "#{PREFIX_ACTION_INTERNAL}#{message}"
log log
end end
@ -202,7 +207,7 @@ class BasicFormatter < SemanticLogger::Formatters::Color # rubocop:disable Metri
def backtrace(stack) def backtrace(stack)
return "\n" unless stack.count.positive? 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 end
def color_content def color_content

Loading…
Cancel
Save