|
|
@ -7,8 +7,7 @@ require 'amazing_print' |
|
|
|
class BasicFormatter < SemanticLogger::Formatters::Color |
|
|
|
NAME_MAX_SIZE = 25 |
|
|
|
TERMINAL_PREFIX = ENV['TERMINAL_PREFIX'].to_i || 0 |
|
|
|
CONTENT_PREFIX = ' '.freeze |
|
|
|
WRAP_PREFIX = ' … '.freeze |
|
|
|
CONTENT_PREFIX = '---'.freeze |
|
|
|
|
|
|
|
ANSI_DEBUG = "\e[90m".freeze |
|
|
|
ANSI_INFO = SemanticLogger::AnsiColors::GREEN |
|
|
@ -57,11 +56,13 @@ class BasicFormatter < SemanticLogger::Formatters::Color |
|
|
|
end |
|
|
|
|
|
|
|
wrap_length = compute_useful_length |
|
|
|
space_prefix = message.match(/^\s*/) |
|
|
|
message = Wrapper.wrap("#{CONTENT_COLOR_MAP[log.level]}#{message}", before_message(true, space_prefix), |
|
|
|
wrap_length - space_prefix.length) |
|
|
|
md = message.match(/^\s*/) |
|
|
|
space_prefix = md.match(0) |
|
|
|
message = md.post_match |
|
|
|
message = Wrapper.wrap("#{CONTENT_COLOR_MAP[log.level]}#{message}", before_message(true) + space_prefix.to_s, |
|
|
|
wrap_length - md.end(0)) |
|
|
|
|
|
|
|
"#{CONTENT_COLOR_MAP[log.level]}#{message}#{color_map.clear}" |
|
|
|
"#{CONTENT_COLOR_MAP[log.level]}#{space_prefix}#{message}#{color_map.clear}" |
|
|
|
end |
|
|
|
|
|
|
|
def payload |
|
|
@ -69,20 +70,28 @@ class BasicFormatter < SemanticLogger::Formatters::Color |
|
|
|
|
|
|
|
lines = log.payload.ai(ruby19_syntax: true, indent: 2).split("\n") |
|
|
|
first_line = lines.shift |
|
|
|
space_prefix = first_line.match(/^\s*/) |
|
|
|
lines = lines.map do |l| |
|
|
|
space_prefix = l.match(/^\s*/) |
|
|
|
"#{before_message(true, space_prefix)}#{l}" |
|
|
|
"#{before_message(true)}#{space_prefix}#{l}" |
|
|
|
end |
|
|
|
lines.unshift(first_line).join("\n") |
|
|
|
result = lines.unshift(first_line).join("\n") |
|
|
|
result.sub!(/\s*/) { |m| '-' * m.length } |
|
|
|
result |
|
|
|
end |
|
|
|
|
|
|
|
def level |
|
|
|
level = case log.level |
|
|
|
when :info then ' ' |
|
|
|
when :debug then 'd' |
|
|
|
else log.level.to_s.chr.upcase |
|
|
|
end |
|
|
|
"#{color}╣#{level}╠#{color_map.clear}" |
|
|
|
case log.level |
|
|
|
when :info, :debug then draw_rails ' ' |
|
|
|
else draw_rails(log.level.to_s.chr.upcase) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
def draw_rails(char) |
|
|
|
"#{color}╣#{char}╠#{color_map.clear}" |
|
|
|
end |
|
|
|
|
|
|
|
def continuation |
|
|
|
draw_rails('┆') |
|
|
|
end |
|
|
|
|
|
|
|
def name |
|
|
@ -109,8 +118,7 @@ class BasicFormatter < SemanticLogger::Formatters::Color |
|
|
|
self.log = log |
|
|
|
self.logger = logger |
|
|
|
|
|
|
|
self.log.payload = |
|
|
|
[before_message, message, payload, exception].compact.join(' ') |
|
|
|
before_message + [message, payload, exception].compact.join(' ') |
|
|
|
end |
|
|
|
|
|
|
|
private |
|
|
@ -118,18 +126,11 @@ class BasicFormatter < SemanticLogger::Formatters::Color |
|
|
|
def compute_useful_length |
|
|
|
wrap_length = IO.console.winsize[1] - TERMINAL_PREFIX - before_message.length + CONTENT_PREFIX.length + 12 |
|
|
|
rescue StandardError |
|
|
|
wrap_length = 100 |
|
|
|
wrap_length = 100 # FIXME: CONSTANTIZE, only useful in DEBUGGER, no IO.console detected! |
|
|
|
end |
|
|
|
|
|
|
|
def before_message(wrapped = false, prefix = '') |
|
|
|
result = [name, level, tags, named_tags, duration, CONTENT_PREFIX].compact.join(' ') |
|
|
|
if wrapped |
|
|
|
[name, level, tags, named_tags, duration, |
|
|
|
"#{color}#{WRAP_PREFIX}#{color_map.clear}#{prefix}"].compact.join(' ') |
|
|
|
else |
|
|
|
[name, level, tags, named_tags, duration, |
|
|
|
CONTENT_PREFIX].compact.join(' ') |
|
|
|
end |
|
|
|
def before_message(wrapped = false) |
|
|
|
[name, wrapped ? continuation : level, tags, named_tags, duration].compact.join(' ') + CONTENT_PREFIX |
|
|
|
end |
|
|
|
|
|
|
|
def backtrace(stack) |
|
|
|