LogManager Class
LogManager for managing scoped Loggers and global sink configuration. More...
Declaration
Public Constructors Index
| LogManager (const LogManager &)=delete | |
Private Constructors Index
| LogManager () | |
|
Creates the LogManager and registers an unscoped default logger. More... | |
Public Destructor Index
| ~LogManager ()=default | |
Public Operators Index
| LogManager & | operator= (const LogManager &)=delete |
Public Member Functions Index
| const Logger & | logger () const noexcept |
|
Returns a const reference to the default logger managed with this LogManager. More... | |
| const Logger & | logger (const std::string &scope) const noexcept |
|
Returns a const reference to the logger instance for the specified scope. More... | |
| Logger & | registerLogger (const std::string &scope) noexcept |
|
Registers a new logger with this manager. More... | |
| void | enableLogging (bool enable) noexcept |
|
Enables or disables all log output of the Loggers registered with this LogManager. More... | |
| void | setScopeFilter (const std::string &scope) noexcept |
|
Sets the filter scope for the logger. More... | |
| void | registerSink (std::shared_ptr< LogSink > sink) |
|
Registers a sink and enables it by default. More... | |
| void | registerSink (std::shared_ptr< LogSink > sink, bool enabled) |
|
Registers a sink with optional auto-enable. More... | |
| void | enableSink (SinkTypeId typeId) |
|
Enables a sink by its type identifier. More... | |
| void | enableSink (std::shared_ptr< LogSink > sink) |
|
Enables a sink, registering it first if necessary. More... | |
| void | disableSink (SinkTypeId typeId) |
|
Disables a sink by its type identifier. More... | |
| void | disableSink (std::shared_ptr< LogSink > sink) |
|
Disables a sink by instance. More... | |
| bool | isSinkEnabled (SinkTypeId typeId) const noexcept |
|
Checks if a sink with the given type identifier is currently enabled. More... | |
| void | enableAllSinks () |
|
Enables all registered sinks. More... | |
| void | disableAllSinks () |
|
Disables all sinks. More... | |
Private Member Functions Index
| void | updateLoggerSinks () |
|
Reconfigures all logger sinks based on currently enabled sinks. More... | |
Private Member Attributes Index
| bool | loggingEnabled_ = LOGGING_ENABLED |
|
Flag indicating whether log output should be globally enabled or disabled. More... | |
| std::unordered_set< std::string > | enabledSinks_ |
|
Set of currently enabled sink type identifiers. More... | |
| std::vector< std::shared_ptr< LogSink > > | registeredSinks_ |
|
Registered sinks (all available sinks, regardless of enabled state). More... | |
| std::unordered_map< std::string, std::unique_ptr< Logger > > | loggers_ |
|
Unordered map holding unique pointers to the loggers managed by this class, guaranteed to be not null. More... | |
| const std::unique_ptr< Logger > | defaultLogger_ |
|
Default logger if a logger for a specific scope was not found. More... | |
| std::mutex | mapMutex_ |
|
Mutex providing mutually exclusive access to the loggers map. More... | |
| std::mutex | sinkMutex_ |
|
Mutex for sink access. More... | |
Public Static Functions Index
| static const Logger & | loggerForScope (const std::string &scope) noexcept |
|
Convenience accessor to obtain a logger for a textual scope via the singleton. More... | |
| static LogManager & | getInstance () noexcept |
|
Returns the LogManager singleton instance. More... | |
Description
LogManager for managing scoped Loggers and global sink configuration.
The LogManager provides centralized control over logging output destinations. Sinks register themselves with a unique type identifier, allowing dynamic enable/disable without compile-time knowledge of all sink types.
```cpp // Register sinks (sinks define their own TYPE_ID) LogManager::getInstance().registerSink(std::make_shared<ConsoleSink>()); LogManager::getInstance().registerSink(std::make_shared<ImGuiLogSink>(widget));
// Enable/disable by type identifier LogManager::getInstance().enableSink("console"); LogManager::getInstance().disableSink("imgui");
// Check status if (LogManager::getInstance().isSinkEnabled("console")) { ... } ```
Definition at line 43 of file LogManager.ixx.
Public Constructors
LogManager()
| delete |
Enforce singleton (see Meyer's Singleton)
Definition at line 139 of file LogManager.ixx.
Private Constructors
LogManager()
| inline |
Creates the LogManager and registers an unscoped default logger.
Definition at line 86 of file LogManager.ixx.
Public Destructor
~LogManager()
| default |
Definition at line 132 of file LogManager.ixx.
Public Operators
operator=()
| delete |
Definition at line 140 of file LogManager.ixx.
Public Member Functions
disableAllSinks()
| inline |
Disables all sinks.
Definition at line 405 of file LogManager.ixx.
disableSink()
| inline |
Disables a sink by its type identifier.
- Parameters
-
typeId The unique type identifier of the sink.
Definition at line 361 of file LogManager.ixx.
Referenced by disableSink.
disableSink()
| inline |
Disables a sink by instance.
- Parameters
-
sink The sink instance to disable.
Definition at line 372 of file LogManager.ixx.
Reference disableSink.
enableAllSinks()
| inline |
Enables all registered sinks.
Definition at line 392 of file LogManager.ixx.
enableLogging()
| inline noexcept |
Enables or disables all log output of the Loggers registered with this LogManager.
- Parameters
-
enable True to enable log output with the registered loggers, otherwise false.
Definition at line 225 of file LogManager.ixx.
enableSink()
| inline |
Enables a sink by its type identifier.
If a sink with the given typeId is registered, it will be enabled. If no sink with that typeId is registered, this call has no effect.
- Parameters
-
typeId The unique type identifier of the sink (e.g., "console", "imgui").
Definition at line 319 of file LogManager.ixx.
enableSink()
| inline |
Enables a sink, registering it first if necessary.
If the sink is not yet registered, it will be added to the pool. The sink is then enabled for output.
- Parameters
-
sink The sink instance to enable (and register if needed).
Definition at line 333 of file LogManager.ixx.
isSinkEnabled()
| inline nodiscard noexcept |
Checks if a sink with the given type identifier is currently enabled.
- Parameters
-
typeId The unique type identifier of the sink.
- Returns
True if the sink is enabled.
Definition at line 384 of file LogManager.ixx.
logger()
| inline nodiscard noexcept |
Returns a const reference to the default logger managed with this LogManager.
- Returns
The default Logger instance.
Definition at line 158 of file LogManager.ixx.
Referenced by registerLogger.
logger()
| inline nodiscard noexcept |
Returns a const reference to the logger instance for the specified scope.
Will fall back to the default logger if the scope was not registered yet. This method is thread safe for map look-ups.
- Parameters
-
scope The textual scope name of the requested logger.
- Returns
The logger registered with the scope, or the default logger if none was found.
Definition at line 173 of file LogManager.ixx.
registerLogger()
| inline nodiscard noexcept |
Registers a new logger with this manager.
This method is thread safe for map modifications.
- Parameters
-
scope The scope requested for the logger to create.
- Returns
The logger registered with the scope, or the logger already registered with the LogManager under the given scope.
Definition at line 195 of file LogManager.ixx.
Reference logger.
Referenced by loggerForScope and setScopeFilter.
registerSink()
| inline |
Registers a sink and enables it by default.
The sink is added to the pool and immediately enabled for output.
- Parameters
-
sink The sink to register.
Definition at line 276 of file LogManager.ixx.
Reference registerSink.
Referenced by registerSink.
registerSink()
| inline |
Registers a sink with optional auto-enable.
- Parameters
-
sink The sink to register.
enabled Whether to enable the sink immediately (default: true).
Definition at line 286 of file LogManager.ixx.
setScopeFilter()
| inline noexcept |
Sets the filter scope for the logger.
Will do nothing if logging is not enabled. If the logger for the scope does not exist, it will get implicitly created.
- Parameters
-
scope The scope to filter. Only log messages with this scope will be logged.
Definition at line 247 of file LogManager.ixx.
References getInstance and registerLogger.
Private Member Functions
updateLoggerSinks()
| inline |
Reconfigures all logger sinks based on currently enabled sinks.
Called internally after sink enable/disable changes.
Definition at line 93 of file LogManager.ixx.
Private Member Attributes
defaultLogger_
|
Default logger if a logger for a specific scope was not found.
Definition at line 71 of file LogManager.ixx.
enabledSinks_
|
Set of currently enabled sink type identifiers.
Definition at line 55 of file LogManager.ixx.
loggers_
|
Unordered map holding unique pointers to the loggers managed by this class, guaranteed to be not null.
Definition at line 66 of file LogManager.ixx.
loggingEnabled_
|
Flag indicating whether log output should be globally enabled or disabled.
Definition at line 50 of file LogManager.ixx.
mapMutex_
| mutable |
Mutex providing mutually exclusive access to the loggers map.
Definition at line 76 of file LogManager.ixx.
registeredSinks_
|
Registered sinks (all available sinks, regardless of enabled state).
Definition at line 60 of file LogManager.ixx.
sinkMutex_
| mutable |
Mutex for sink access.
Definition at line 81 of file LogManager.ixx.
Public Static Functions
getInstance()
| inline noexcept static |
Returns the LogManager singleton instance.
- Returns
Reference to the global LogManager instance.
Definition at line 147 of file LogManager.ixx.
Referenced by loggerForScope and setScopeFilter.
loggerForScope()
| inline noexcept static |
Convenience accessor to obtain a logger for a textual scope via the singleton.
This static helper forwards to `LogManager::getInstance().logger(scope)` and returns a reference to the logger registered for the given scope.
- Parameters
-
scope The textual scope name of the requested logger.
- Returns
The logger registered with the scope, or the default logger if none was found.
Definition at line 128 of file LogManager.ixx.
References getInstance and registerLogger.
The documentation for this class was generated from the following file:
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.