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.%3
N"))
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)
Sourceasync_mode?
Whether async dispatch mode is enabled (affects close behavior)
Sourcebackend
Installed backend (nil when logging disabled or closed)
SourceInstalled backend (nil when logging disabled or closed)
Sourceclose
Closes the logging backend and its file.
Detaching the backend first prevents new entries while Backend#close
drains its async dispatcher. The file must remain open until that drain
completes. Called automatically by Termisu.close.
Sourceflush
Flushes any buffered log entries to disk.
In async mode, yields first to let dispatch fiber process.
Sourcelog_file
Open log file handle (nil when logging disabled)
Sourcelog_file=(log_file :
File |
Nil)
Open log file handle (nil when logging disabled)
Sourcesetup
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