module Termisu::Logging

Overview

Logging configuration and lifecycle management.

Handles setup, configuration, and cleanup of the logging system. Called automatically by Termisu.new and Termisu.close.

Defined in:

termisu/log.cr

Constant Summary

FORMATTER = ::Log::Formatter.new do |entry, io| io << (entry.timestamp.to_s("%Y-%m-%d %H:%M:%S.%3N")) io << " [" io << (entry.severity.to_s.upcase.ljust(5)) io << "] " io << entry.source io << ": " io << entry.message if data = entry.context data.each do |key, value| (((io << " ") << key) << "=") << value end end if ex = entry.exception (((io << "\n Exception: ") << ex.class.name) << ": ") << ex.message if bt = ex.backtrace? (bt.first(5)).each do |line| (io << "\n ") << line end end end end

Custom formatter for Termisu logs

LEVELS = {"trace" => ::Log::Severity::Trace, "debug" => ::Log::Severity::Debug, "info" => ::Log::Severity::Info, "notice" => ::Log::Severity::Notice, "warn" => ::Log::Severity::Warn, "error" => ::Log::Severity::Error, "fatal" => ::Log::Severity::Fatal, "none" => ::Log::Severity::None}

Severity level name to Log::Severity mapping

MUTEX = Mutex.new(:unchecked)

Class Method Summary

Class Method Detail

def self.async_mode=(async_mode : Bool) #

Whether async dispatch mode is enabled (affects close behavior)


[View source]
def self.async_mode? : Bool #

Whether async dispatch mode is enabled (affects close behavior)


[View source]
def self.backend : ::Log::IOBackend | Nil #

Installed backend (nil when logging disabled or closed)


[View source]
def self.backend=(backend : ::Log::IOBackend | Nil) #

Installed backend (nil when logging disabled or closed)


[View source]
def self.close : Nil #

Unbinds Termisu loggers before draining their backend, then flushes and closes the file. Every cleanup step runs and the first error is re-raised.


[View source]
def self.configured=(configured : Bool) #

Whether logging has been configured (prevents duplicate setup)


[View source]
def self.configured? : Bool #

Whether logging has been configured (prevents duplicate setup)


[View source]
def self.flush : Nil #

Drains all entries accepted before this call and flushes the file buffer.


[View source]
def self.log_file : File | Nil #

Open log file handle (nil when logging disabled)


[View source]
def self.log_file=(log_file : File | Nil) #

Open log file handle (nil when logging disabled)


[View source]
def self.setup : Nil #

Configures logging based on environment variables.

Setup failures retain the existing best-effort behavior: Termisu remains usable with its isolated loggers disabled.


[View source]