๐ Log โ
The Log module is the global bridge between Xila logging calls and a concrete backend implementation.
Role in system โ
- Provides uniform log macros (
error!,warning!,information!,debug!,trace!) across modules. - Adapts Xila-specific
LoggerTraitto the externallogcrate runtime. - Centralizes level filtering and formatted record emission policy.
Responsibilities and boundaries โ
In scope
- Global logger initialization and registration.
- Severity-level mapping and default formatting.
- Backend trait abstraction (
enabled,write, optionalflush).
Out of scope
- Transport/storage mechanics (console, serial, file, remote).
- Advanced aggregation/query infrastructure.
Internal architecture โ
LOGGER_INSTANCE: OnceLock<Logger>stores single logger adapter.LoggerTraitis backend contract;Loggeradapter implementslog_external::Log.Recordstructure captures normalized level/target/arguments.- Default
LoggerTrait::logformatting decorates lines with level tag and ANSI color tokens.
Contract vs implementation
- Contract: backend
LoggerTraitmethods and macro-level behavior. - Implementation: concrete formatting/color tokens and
set_max_levelpolicy.
Lifecycle and execution model โ
- Platform creates backend implementing
LoggerTrait. - Runtime calls
log::initialize(...)once. - Module macros emit through
logecosystem into adapter and backend sink.
Data/control flow โ
- Macro invocation ->
log_external->Loggeradapter ->LoggerTrait::enabled/log/write. - Initialization attempts after first registration do not replace logger; they emit an error log.
Concurrency and synchronization model โ
- Singleton registration guarded by
OnceLock. - Thread-safety at runtime relies on backend
LoggerTrait: Send + Syncand backend internals.
Dependency model โ
- Depends on
logecosystem crate for macro/runtime integration. - Consumed by nearly all core modules for diagnostics.
Failure semantics and recovery behavior โ
initializereturnsOk(())even if logger was already set inlogruntime; duplicate init is reported via error record.- Backend write/flush behavior is backend-defined; module itself does not buffer/retry.
Extension points โ
- Provide alternative backend implementations for each platform.
- Override
LoggerTrait::logfor custom formatting or structured payload conventions. - Add runtime filtering policy in backend or wrapper layer.
Known limitations and trade-offs โ
- Single global logger; dynamic replacement/reconfiguration is limited.
- Formatting includes ANSI control sequences by default, which may be undesirable in non-terminal sinks unless backend adapts.
- Reliability guarantees (buffering, durability) are sink-specific.