|
@ -1,4 +1,4 @@ |
|
|
# My Custom colorized formatter |
|
|
|
|
|
|
|
|
# Opinioned Rails custom formatter |
|
|
class BasicFormatter < SemanticLogger::Formatters::Color |
|
|
class BasicFormatter < SemanticLogger::Formatters::Color |
|
|
NAME_MAX_SIZE = 25 |
|
|
NAME_MAX_SIZE = 25 |
|
|
|
|
|
|
|
@ -12,18 +12,28 @@ class BasicFormatter < SemanticLogger::Formatters::Color |
|
|
ANSI_REVERSED_ERROR = "\e[1;30;41m".freeze |
|
|
ANSI_REVERSED_ERROR = "\e[1;30;41m".freeze |
|
|
ANSI_REVERSED_FATAL = "\e[1;30;41m".freeze |
|
|
ANSI_REVERSED_FATAL = "\e[1;30;41m".freeze |
|
|
|
|
|
|
|
|
|
|
|
CONTENT_COLOR_MAP = ColorMap.new( |
|
|
|
|
|
debug: ANSI_DEBUG, |
|
|
|
|
|
info: ANSI_NEUTRAL_INFO, |
|
|
|
|
|
warn: ANSI_REVERSED_WARNING, |
|
|
|
|
|
error: ANSI_REVERSED_ERROR, |
|
|
|
|
|
fatal: ANSI_REVERSED_FATAL |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
def initialize |
|
|
def initialize |
|
|
super(time_format: nil, |
|
|
|
|
|
color_map: ColorMap.new(debug: ANSI_DEBUG, info: ANSI_INFO, warn: ANSI_WARN, error: ANSI_ERROR, |
|
|
|
|
|
fatal: ANSI_ERROR)) |
|
|
|
|
|
@content_color_map = ColorMap.new(debug: ANSI_DEBUG, info: ANSI_NEUTRAL_INFO, warn: ANSI_REVERSED_WARNING, |
|
|
|
|
|
error: ANSI_REVERSED_ERROR, fatal: ANSI_REVERSED_FATAL) |
|
|
|
|
|
|
|
|
super(color_map: ColorMap.new( |
|
|
|
|
|
debug: ANSI_DEBUG, |
|
|
|
|
|
info: ANSI_INFO, |
|
|
|
|
|
warn: ANSI_WARN, |
|
|
|
|
|
error: ANSI_ERROR, |
|
|
|
|
|
fatal: ANSI_ERROR |
|
|
|
|
|
)) |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
def message |
|
|
def message |
|
|
return unless log.message |
|
|
return unless log.message |
|
|
|
|
|
|
|
|
" #{@content_color_map[log.level]}#{log.message}#{color_map.clear}" |
|
|
|
|
|
|
|
|
" #{CONTENT_COLOR_MAP[log.level]}#{log.message}#{color_map.clear}" |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
def level |
|
|
def level |
|
@ -35,19 +45,11 @@ class BasicFormatter < SemanticLogger::Formatters::Color |
|
|
"#{ANSI_DEBUG}#{log.name.truncate(NAME_MAX_SIZE).center(NAME_MAX_SIZE)}#{color_map.clear}" |
|
|
"#{ANSI_DEBUG}#{log.name.truncate(NAME_MAX_SIZE).center(NAME_MAX_SIZE)}#{color_map.clear}" |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
def process_info |
|
|
|
|
|
fname = file_name_and_line |
|
|
|
|
|
"#{color}[#{fname}]#{color_map.clear}" if fname |
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def exception |
|
|
def exception |
|
|
return unless log.exception |
|
|
return unless log.exception |
|
|
|
|
|
|
|
|
root_path = Rails.root.to_s |
|
|
root_path = Rails.root.to_s |
|
|
backtrace = log.exception.backtrace.select do |line| |
|
|
|
|
|
line.starts_with?(root_path) |
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
backtrace = log.exception.backtrace.select { |line| line.starts_with?(root_path) } |
|
|
if backtrace.count.positive? |
|
|
if backtrace.count.positive? |
|
|
"-- #{ANSI_REVERSED_ERROR}#{log.exception.class}#{color_map.clear} #{color}#{log.exception.message}\n#{color} ↳ #{backtrace.join("\n ↳ ")}#{color_map.clear}\n\n" |
|
|
"-- #{ANSI_REVERSED_ERROR}#{log.exception.class}#{color_map.clear} #{color}#{log.exception.message}\n#{color} ↳ #{backtrace.join("\n ↳ ")}#{color_map.clear}\n\n" |
|
|
else |
|
|
else |
|
|