Browse Source

Completed

main
pvincent 6 months ago
parent
commit
66aa4f1720
  1. 26
      lib/formatters/ansi_formatter.rb

26
lib/formatters/ansi_formatter.rb

@ -17,6 +17,7 @@ class AnsiFormatter < SemanticLogger::Formatters::Color
CHAR_FATAL = '⯶'.freeze
TERMINUS_STRING = '╙─╜'.freeze
RENDERED_VIEW_DURATION = 100
TOTAL_RENDERED_VIEW_DURATION = RENDERED_VIEW_DURATION * 5
def initialize
super(color_map:
@ -71,15 +72,22 @@ class AnsiFormatter < SemanticLogger::Formatters::Color
log.dimensions = AnsiDimensions.new(rails:, before:)
@memory = nil
log.message = two_captures_last_as_bold(log.message, /(^Started \w* )"(.*?)"/)
elsif log.message.starts_with?('Completed 2')
log.dimensions = AnsiDimensions.new(rails: TERMINUS_STRING, after: 1)
elsif log.message.starts_with?('Completed 3')
@memory = '║'
log.dimensions = AnsiDimensions.new(rails: "#{@memory}")
elsif log.message.starts_with?('Completed 4')
log.dimensions = AnsiDimensions.new(rails: '╙╨╜')
elsif log.message.starts_with?('Completed 5')
log.dimensions = AnsiDimensions.new(rails: "#{draw_fatal}")
elsif log.message.starts_with?('Completed')
m1, m2, m3, m4 = log.message.match(/^Completed (\d+) (.*) in (\d+\.?\d*)ms (.*)$/).captures
http_code = m1.to_i
duration = m3.to_f
duration = duration > TOTAL_RENDERED_VIEW_DURATION ? " in #{m3}ms #{m4}" : ''
log.message = "Completed #{BOLD}#{http_code}#{CLEAR} #{m2}#{duration}"
if http_code / 100 == 2
log.dimensions = AnsiDimensions.new(rails: TERMINUS_STRING, after: 1)
elsif http_code / 100 == 3
@memory = '║'
log.dimensions = AnsiDimensions.new(rails: "#{@memory}")
elsif http_code / 100 == 4
log.dimensions = AnsiDimensions.new(rails: '╙╨╜')
elsif http_code / 100 == 5
log.dimensions = AnsiDimensions.new(rails: "#{draw_fatal}")
end
elsif log.message =~ /^(Processing|Parameters)/
log.level = :debug
if log.message =~ /^Processing/

Loading…
Cancel
Save