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. | |
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);
| Logger::Logger | ( | ) |
Definition at line 19 of file Logger.cpp.
| Logger::~Logger | ( | ) |
Definition at line 23 of file Logger.cpp.
| void Logger::activateDeferred | ( | LogBackendId | id | ) |
Called by a backend that deferred its own activation on some background precondition (eg.
Definition at line 147 of file Logger.cpp.
|
inline |
| 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.
| 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.
| 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.
Definition at line 31 of file Logger.cpp.
| 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.
| 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.
|
static |