libgui 2.01
libgui is a GUI library for the GameCube, Wii, and Wii U
 
Loading...
Searching...
No Matches
Logger Class Reference

Central fan-out dispatcher. More...

#include <Logger.h>

Public Member Functions

 Logger (const Logger &)=delete
 
Logger & operator= (const Logger &)=delete
 
void init (const LogConfig &config)
 Applies config, calling init()/shutdown() on registered backends as needed so only the ones actually selected by config are live.
 
void activateDeferred (LogBackendId id)
 Called by a backend that deferred its own activation on some background precondition (eg.
 
void shutdown ()
 Shuts down every registered backend and forgets the config.
 
bool registerBackend (LogBackendId id, LoggingDriver *backend)
 Registers a backend under the given single-bit LogBackendId, for later selection via LogConfig::mode / multiBackendMask.
 
void setLevel (LogLevel level)
 Runtime-adjusts the minimum severity without touching any other config field or re-touching backend init/shutdown.
 
LogLevel getLevel () const
 
void log (LogLevel level, const char *fmt, va_list args)
 Formats fmt/args into a fixed stack buffer and fans it out to every backend selected by the current config.
 

Static Public Attributes

static const int MAX_BACKENDS = 8
 Maximum number of backends that can be registered at once.
 

Detailed Description

Central fan-out dispatcher.

Concrete (not abstract) - there is exactly one Logger, owned by Platform, and every platform builds the same kind of Logger with a different set of backends registered into it.

Usage from a Platform::init(): logger = new Logger(); logger->registerBackend(LOGGER_OSREPORT, new WutOSReportLogBackend()); logger->registerBackend(LOGGER_UDP, new WutUdpLogBackend()); logger->init(LogConfig{}); // defaults: OSReport only, Info level

Usage from anywhere else in the app, no platform-specific code needed: LOG_INFO("mounted %d devices", count);

Definition at line 190 of file Logger.h.

Constructor & Destructor Documentation

◆ Logger()

Logger::Logger ( )

Definition at line 19 of file Logger.cpp.

◆ ~Logger()

Logger::~Logger ( )

Definition at line 23 of file Logger.cpp.

Member Function Documentation

◆ activateDeferred()

void Logger::activateDeferred ( LogBackendId id)

Called by a backend that deferred its own activation on some background precondition (eg.

OgcLoggerUdp)

Definition at line 147 of file Logger.cpp.

◆ getLevel()

LogLevel Logger::getLevel ( ) const
inline
Returns
the current minimum severity

Definition at line 231 of file Logger.h.

◆ init()

void Logger::init ( const LogConfig & config)

Applies config, calling init()/shutdown() on registered backends as needed so only the ones actually selected by config are live.

Safe to call again later (eg. a settings menu flipping LogMode at runtime) - it reconciles against whatever was previously active rather than assuming this is the first call.

Definition at line 83 of file Logger.cpp.

◆ log()

void Logger::log ( LogLevel level,
const char * fmt,
va_list args )

Formats fmt/args into a fixed stack buffer and fans it out to every backend selected by the current config.

No-ops (cheaply) if level is below the configured minimum or Logger hasn't been init()'d. Called by the LOG_*() macros via LogPrintf() below - application code should not normally call this directly.

Definition at line 215 of file Logger.cpp.

◆ registerBackend()

bool Logger::registerBackend ( LogBackendId id,
LoggingDriver * backend )

Registers a backend under the given single-bit LogBackendId, for later selection via LogConfig::mode / multiBackendMask.

Logger takes ownership (deletes it in ~Logger()). At most one backend may be registered per id; a duplicate registration deletes backend and returns false rather than leaking it or silently replacing the existing one.

Returns
false if id is not a single bit, MAX_BACKENDS slots are already used, or id is already registered.

Definition at line 31 of file Logger.cpp.

◆ setLevel()

void Logger::setLevel ( LogLevel level)

Runtime-adjusts the minimum severity without touching any other config field or re-touching backend init/shutdown.

Definition at line 197 of file Logger.cpp.

◆ shutdown()

void Logger::shutdown ( )

Shuts down every registered backend and forgets the config.

Backends themselves remain registered (and owned) until this Logger is destroyed, so a later init() call can reactivate them without re-registering.

Definition at line 170 of file Logger.cpp.

Member Data Documentation

◆ MAX_BACKENDS

const int Logger::MAX_BACKENDS = 8
static

Maximum number of backends that can be registered at once.

Definition at line 241 of file Logger.h.


The documentation for this class was generated from the following files: