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

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.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.


[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 #

Flushes any buffered log entries to disk.

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


[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 #

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.


[View source]