Logging Colorization Colorize Hanami logger with your custom palette
Logging Colorization
Hanami uses a default color palette for standard output logging.
Custom colorizer
You can build your own colorization strategy:
# config/environment.rb
# ...
require_relative "./logger_colorizer"
Hanami.configure do
# ...
environment :development do
logger level: :info, colorizer: LoggerColorizer.new
end
end
# config/logger_colorizer.rb
require "hanami/logger"
require "paint" # gem install paint
class LoggerColorizer < Hanami::Logger::Colorizer
def initialize(colors: { app: [:red, :bright], severity: [:red, :blue], datetime: [:italic, :yellow] })
super
end
private
def colorize(message, color:)
Paint[message, *color]
end
end
Disable colorization
In order to disable the colorization:
# config/environment.rb
# ...
Hanami.configure do
# ...
environment :development do
logger level: :info, colorizer: false
end
end