Class: Makit::Logging::StructuredFormatter Deprecated

Inherits:
Logger::Formatter
  • Object
show all
Defined in:
lib/makit/logging.rb

Overview

Deprecated.

This class is deprecated and will be removed in version 0.2.0. Use Makit::Logging::Logger with Makit::Logging::Sinks::FileSink (formatter: :json) instead.

Structured JSON log formatter

This formatter outputs log messages as JSON objects with structured fields including timestamp, level, message, and program name. Useful for log aggregation systems and machine parsing.

Instance Method Summary collapse

Instance Method Details

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

Format a log message as JSON

Parameters:

  • severity (String)

    log level (DEBUG, INFO, WARN, ERROR, FATAL)

  • time (Time)

    timestamp of the log message

  • progname (String)

    program name

  • msg (String)

    the log message content

Returns:

  • (String)

    JSON formatted log entry with newline



209
210
211
212
213
214
215
216
217
218
# File 'lib/makit/logging.rb', line 209

def call(severity, time, progname, msg)
  warn "Makit::Logging::StructuredFormatter is deprecated and will be removed in version 0.2.0. Use Makit::Logging::Logger with Makit::Logging::Sinks::FileSink (formatter: :json) instead."
  timestamp = time.strftime("%Y-%m-%d %H:%M:%S.%L")
  {
    timestamp: timestamp,
    level: severity,
    message: msg,
    progname: progname,
  }.to_json + "\n"
end