Class: Securial::Logger::Formatter::ColorfulFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/securial/logger/formatter.rb

Overview

Formatter that adds color to log output for terminal display.

This formatter colorizes log messages based on their severity level, making them easier to distinguish in terminal output. It follows the standard Ruby Logger formatter interface.

Examples:

logger = Logger.new(STDOUT)
logger.formatter = Securial::Logger::Formatter::ColorfulFormatter.new

Instance Method Summary collapse

Instance Method Details

#call(severity, timestamp, progname, msg) ⇒ String

Formats a log message with color based on severity.

Parameters:

  • severity (String)

    Log severity level (DEBUG, INFO, etc.)

  • timestamp (Time)

    Time when the log event occurred

  • progname (String)

    Program name or context for the log message

  • msg (String)

    The log message itself

Returns:

  • (String)

    Formatted log message with appropriate ANSI color codes



71
72
73
74
75
76
77
# File 'lib/securial/logger/formatter.rb', line 71

def call(severity, timestamp, progname, msg)
  color = COLORS[severity] || CLEAR
  padded_severity = severity.ljust(SEVERITY_WIDTH)
  formatted = "[#{progname}][#{timestamp.strftime("%Y-%m-%d %H:%M:%S")}] #{padded_severity} -- #{msg}\n"

  "#{color}#{formatted}#{CLEAR}"
end