|
@ -15,6 +15,8 @@ class AnsiFormatter < SemanticLogger::Formatters::Color |
|
|
ANSI_ERROR = CLEAR + BG_RED + TEXT_WHITE |
|
|
ANSI_ERROR = CLEAR + BG_RED + TEXT_WHITE |
|
|
ANSI_FATAL = CLEAR + BG_MAGENTA + BOLD + TEXT_WHITE |
|
|
ANSI_FATAL = CLEAR + BG_MAGENTA + BOLD + TEXT_WHITE |
|
|
NAME_MAX_SIZE = 20 |
|
|
NAME_MAX_SIZE = 20 |
|
|
|
|
|
FOREMAN_PREFIX_LENGTH = 18 |
|
|
|
|
|
DEFAULT_UNDETECTED_WRAP = 80 |
|
|
|
|
|
|
|
|
def initialize |
|
|
def initialize |
|
|
super(color_map: ColorMap.new( |
|
|
super(color_map: ColorMap.new( |
|
@ -30,7 +32,8 @@ class AnsiFormatter < SemanticLogger::Formatters::Color |
|
|
self.log = log |
|
|
self.log = log |
|
|
self.logger = logger |
|
|
self.logger = logger |
|
|
self.color = color_map[log.level] |
|
|
self.color = color_map[log.level] |
|
|
wrap_level(level, message, payload, exception) |
|
|
|
|
|
|
|
|
wrap_length = compute_useful_length |
|
|
|
|
|
wrap_level(level, wrap_length, message, payload, exception) |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
def origin |
|
|
def origin |
|
@ -56,6 +59,12 @@ class AnsiFormatter < SemanticLogger::Formatters::Color |
|
|
|
|
|
|
|
|
private |
|
|
private |
|
|
|
|
|
|
|
|
|
|
|
def compute_useful_length |
|
|
|
|
|
IO.console.winsize[1] - FOREMAN_PREFIX_LENGTH |
|
|
|
|
|
rescue StandardError |
|
|
|
|
|
DEFAULT_UNDETECTED_WRAP |
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
def clean_backtrace(backtrace) |
|
|
def clean_backtrace(backtrace) |
|
|
root_path = Rails.root.to_s |
|
|
root_path = Rails.root.to_s |
|
|
backtrace = backtrace.select { |line| line.starts_with?(root_path) } |
|
|
backtrace = backtrace.select { |line| line.starts_with?(root_path) } |
|
@ -67,11 +76,11 @@ class AnsiFormatter < SemanticLogger::Formatters::Color |
|
|
"#{tint}#{text}#{AnsiColors::CLEAR}" |
|
|
"#{tint}#{text}#{AnsiColors::CLEAR}" |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
def wrap_level(level, *items) |
|
|
|
|
|
|
|
|
def wrap_level(level, length, *items) |
|
|
prefix = "#{origin} #{colorize('>')} " |
|
|
prefix = "#{origin} #{colorize('>')} " |
|
|
continuation = "#{origin} #{colorize('#')} " |
|
|
continuation = "#{origin} #{colorize('#')} " |
|
|
items.map do |item| |
|
|
items.map do |item| |
|
|
AnsiWrapper.wrap(item, 100, prefix, continuation) |
|
|
|
|
|
|
|
|
AnsiWrapper.wrap(item, length, prefix, continuation) |
|
|
end.compact.join("\n") # FIXME: previously was: join(' ') |
|
|
end.compact.join("\n") # FIXME: previously was: join(' ') |
|
|
end |
|
|
end |
|
|
end |
|
|
end |