class

Logarithm::StructuredLogger

Inherits Reference < Object

Enhanced logger with structured logging support

This class provides centralized logging capabilities with support for both human-readable text format and structured JSON format. Includes audit trail functionality and performance-optimized logging.

Features

  • Structured JSON logging
  • Audit trail support
  • Configurable output format
  • Log file rotation

Configuration

Environment variables:

  • LOG_FORMAT: JSON, TEXT (default: TEXT)
  • LOG_FILE: Optional log file path

Usage

logger = StructuredLogger.new
logger.log(Log::Severity::Info, "Message") do |entry|
  entry.context = {"key" => "value"}
end

Constructors

new(io : IO)

Constructor for testing with custom IO

Source

Instance methods

log(level : ::Log::Severity, message : String, & : LogEntry -> Nil)
Source
log(level : ::Log::Severity, message : String)
Source
setup_log_level
Source