module

Termisu::Logging

Logging configuration and lifecycle management.

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

Constants

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

Class methods

async_mode=(async_mode : Bool)

Whether async dispatch mode is enabled (affects close behavior)

Source
async_mode?

Whether async dispatch mode is enabled (affects close behavior)

Source
close

Closes the log file and cleans up resources.

In async mode, yields to let the dispatch fiber process pending logs before closing. Called automatically by Termisu.close.

Source
configured=(configured : Bool)

Whether logging has been configured (prevents duplicate setup)

Source
configured?

Whether logging has been configured (prevents duplicate setup)

Source
flush

Flushes any buffered log entries to disk.

In async mode, yields first to let dispatch fiber process.

Source
log_file

Open log file handle (nil when logging disabled)

Source
log_file=(log_file : File | Nil)

Open log file handle (nil when logging disabled)

Source
setup

Configures logging based on environment variables.

Reads TERMISU_LOG_LEVEL, TERMISU_LOG_FILE, and TERMISU_LOG_SYNC to configure the logging backend. Called automatically by Termisu.new.

In async mode (default), uses async dispatch with SafeFileIO wrapper. In sync mode, uses direct dispatch for real-time logging.

Source