Browse Source

ansi_filter

main
pvincent 6 months ago
parent
commit
db607ed330
  1. 44
      lib/formatters/ansi_filter.rb

44
lib/formatters/ansi_filter.rb

@ -1,32 +1,44 @@
require_relative 'ansi_dimensions' require_relative 'ansi_dimensions'
require_relative 'ansi_colors'
# filter log message # filter log message
module AnsiFilter module AnsiFilter
$memory = nil $memory = nil
CHAR_FATAL = '⯶'.freeze
def self.reject(log) def self.reject(log)
# log.name == 'ScoresController' || false # log.name == 'ScoresController' || false
false false
end end
def self.alter(log) def self.alter(log)
if log.name == 'Rails' && log.message
log.message.chomp!('')
if log.message.starts_with?('Started')
rails = '╓─╖'
rails = "#{$memory}" if $memory
log.dimensions = AnsiDimensions.new(rails:)
$memory = nil
elsif log.message.starts_with?('Completed 2')
log.dimensions = AnsiDimensions.new(rails: '╙─╜', after: 2)
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: '╙⯶╜')
if log.name == 'Rails'
if log.message
log.message.chomp!('')
if log.message.starts_with?('Started')
rails = '╓─╖'
rails = "#{$memory}" if $memory
log.dimensions = AnsiDimensions.new(rails:)
$memory = nil
elsif log.message.starts_with?('Completed 2')
log.dimensions = AnsiDimensions.new(rails: '╙─╜', after: 2)
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}")
end
elsif log.exception
log.dimensions = AnsiDimensions.new(rails: "#{draw_fatal(log.level.to_s.chr.upcase)}", after: 2)
end end
end end
log log
end end
private_class_method def self.draw_fatal(char = CHAR_FATAL)
AnsiColors::BG_MAGENTA + AnsiColors::BOLD + AnsiColors::TEXT_WHITE + char + AnsiColors::CLEAR
end
end end
Loading…
Cancel
Save