Browse Source

compute_wrap_length

main
pvincent 6 months ago
parent
commit
b989a2c3f4
  1. 12
      app/controllers/scores_controller.rb
  2. 2
      config/database.yml
  3. 15
      lib/formatters/ansi_formatter.rb

12
app/controllers/scores_controller.rb

@ -32,16 +32,16 @@ class ScoresController < ApplicationController
logger.info(BG_WHITE + TEXT_GRAY_200 + "this is #{BOLD}a message in bold#{CLEAR}, isnt'it?")
logger.info(BG_WHITE + TEXT_GRAY_100 + "this is #{BOLD}a message in bold#{CLEAR}, isnt'it?")
# logger.info({ one: 1, two: 2 })
# logger.info 'this is an information', { four: 4, five: 5 }
logger.info({ one: 1, two: 2 })
logger.info 'this is an information', { four: 4, five: 5 }
logger.debug BigDecimal('0.0003')
# logger.warn 'scores are', @scores
logger.warn 'scores are', @scores
logger.warn "this is a #{BOLD}warning#{CLEAR}#{BG_YELLOW}#{TEXT_BLACK}\n yop\n cool"
logger.warn "this is a warning\n yop\n cool"
logger.error 'this is an error message'
# logger.error "error message line #1\nerror message line #2\nerror message line #3\n\n"
# logger.info 'end of normal message'
# logger.debug @scores
logger.error "error message line #1\nerror message line #2\nerror message line #3\n\n"
logger.info 'end of normal message'
logger.debug @scores
# sleep 0.5
end

2
config/database.yml

@ -6,7 +6,7 @@ default: &default
# For details on connection pooling, see Rails configuration guide
# https://guides.rubyonrails.org/configuring.html#database-pooling
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
host: localhost
host: ct1.lxd
development:
<<: *default

15
lib/formatters/ansi_formatter.rb

@ -15,6 +15,8 @@ class AnsiFormatter < SemanticLogger::Formatters::Color
ANSI_ERROR = CLEAR + BG_RED + TEXT_WHITE
ANSI_FATAL = CLEAR + BG_MAGENTA + BOLD + TEXT_WHITE
NAME_MAX_SIZE = 20
FOREMAN_PREFIX_LENGTH = 18
DEFAULT_UNDETECTED_WRAP = 80
def initialize
super(color_map: ColorMap.new(
@ -30,7 +32,8 @@ class AnsiFormatter < SemanticLogger::Formatters::Color
self.log = log
self.logger = logger
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
def origin
@ -56,6 +59,12 @@ class AnsiFormatter < SemanticLogger::Formatters::Color
private
def compute_useful_length
IO.console.winsize[1] - FOREMAN_PREFIX_LENGTH
rescue StandardError
DEFAULT_UNDETECTED_WRAP
end
def clean_backtrace(backtrace)
root_path = Rails.root.to_s
backtrace = backtrace.select { |line| line.starts_with?(root_path) }
@ -67,11 +76,11 @@ class AnsiFormatter < SemanticLogger::Formatters::Color
"#{tint}#{text}#{AnsiColors::CLEAR}"
end
def wrap_level(level, *items)
def wrap_level(level, length, *items)
prefix = "#{origin} #{colorize('>')} "
continuation = "#{origin} #{colorize('#')} "
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
end
Loading…
Cancel
Save