Class: CMDx::LogFormatters::Line

Inherits:
Object
  • Object
show all
Defined in:
lib/cmdx/log_formatters/line.rb

Overview

Formats log messages as single-line text for human-readable logging

This formatter converts log entries into a compact single-line format with severity abbreviation, ISO8601 timestamp, process ID, and formatted message. The output is optimized for human readability and traditional log file formats.

Instance Method Summary collapse

Instance Method Details

#call(severity, time, progname, message) ⇒ String

Formats a log entry as a single-line string

Examples:

Basic usage

logger_formatter.call("INFO", Time.now, "MyApp", "User logged in")
# => "I, [2024-01-15T10:30:45.123456Z #12345] INFO -- MyApp: User logged in\n"

Parameters:

  • severity (String)

    The log level (e.g., “INFO”, “ERROR”, “DEBUG”)

  • time (Time)

    The timestamp when the log entry was created

  • progname (String, nil)

    The program name or identifier

  • message (Object)

    The log message content

Returns:

  • (String)

    A single-line formatted log entry with a trailing newline



26
27
28
# File 'lib/cmdx/log_formatters/line.rb', line 26

def call(severity, time, progname, message)
  "#{severity[0]}, [#{time.utc.iso8601(6)} ##{Process.pid}] #{severity} -- #{progname}: #{message}\n"
end