![]() |
LogIt++
|
Singleton class managing multiple loggers and formatters. More...
#include <Logger.hpp>
Classes | |
struct | LoggerStrategy |
Structure to hold a logger-formatter pair. More... | |
Public Member Functions | |
void | add_logger (std::unique_ptr< ILogger > logger, std::unique_ptr< ILogFormatter > formatter, bool single_mode=false) |
Adds a logger and its corresponding formatter. | |
void | set_logger_enabled (int logger_index, bool enabled) |
Enables or disables a logger by index. | |
bool | is_logger_enabled (int logger_index) const |
Checks if a logger is enabled. | |
void | set_logger_single_mode (int logger_index, bool single_mode) |
Sets single-mode flag for a logger. | |
void | set_timestamp_offset (int logger_index, int64_t offset_ms) |
Sets timestamp offset for a specific logger. | |
void | set_log_level (LogLevel level) |
Sets minimal log level for all loggers. | |
void | set_log_level (int logger_index, LogLevel level) |
Sets minimal log level for a specific logger. | |
bool | is_logger_single_mode (int logger_index) const |
Checks whether a logger is in single mode. | |
void | log (const LogRecord &record) |
Logs a LogRecord using added loggers and formatters. | |
std::string | get_string_param (int logger_index, const LoggerParam ¶m) const |
Retrieves a string parameter from a logger. | |
int64_t | get_int_param (int logger_index, const LoggerParam ¶m) const |
Retrieves an integer parameter from a logger. | |
double | get_float_param (int logger_index, const LoggerParam ¶m) const |
Retrieves a floating-point parameter from a logger. | |
template<typename... Ts> | |
auto | log_and_return (const LogRecord &record, Ts &&... args) -> decltype(std::forward_as_tuple(std::forward< Ts >(args)...)) |
Logs message and returns tuple of arguments. | |
template<typename T> | |
auto | log_and_return (const LogRecord &record, T &&args) -> decltype(args) |
Logs message and returns argument. | |
auto | log_and_return (const LogRecord &record) -> std::tuple<> |
Logs message without arguments and returns empty tuple. | |
void | wait () |
Waits for all asynchronous loggers to finish processing. | |
void | shutdown () |
Shuts down logger system. | |
Static Public Member Functions | |
static Logger & | get_instance () |
Retrieves singleton instance of Logger. | |
Private Member Functions | |
void | print (const LogRecord &record) |
template<typename... Ts> | |
void | print (const LogRecord &record, Ts const &... args) |
Logs a record with given arguments. | |
Logger () | |
~Logger () | |
Logger (const Logger &)=delete | |
Logger & | operator= (const Logger &)=delete |
Logger (Logger &&)=delete | |
Logger & | operator= (Logger &&)=delete |
Static Private Member Functions | |
static void | on_exit_handler () |
Atexit shutdown handler for Logger and TaskExecutor. | |
Private Attributes | |
std::vector< LoggerStrategy > | m_loggers |
Container for logger-formatter pairs. | |
std::mutex | m_mutex |
Mutex for thread safety during logging operations. | |
std::atomic< bool > | m_shutdown = ATOMIC_VAR_INIT(false) |
Flag indicating if shutdown was requested. | |
Singleton class managing multiple loggers and formatters.
Allows adding multiple logger and formatter pairs. Provides methods to log messages using these strategies and supports both synchronous and asynchronous logging. Class is thread-safe.
Definition at line 24 of file Logger.hpp.
|
inlineprivate |
Definition at line 290 of file Logger.hpp.
|
inlineprivate |
Definition at line 294 of file Logger.hpp.
|
privatedelete |
|
privatedelete |
|
inline |
Adds a logger and its corresponding formatter.
logger | Unique pointer to a logger instance. |
formatter | Unique pointer to a formatter instance. |
single_mode | If true, this logger will only be invoked by specific log macros (e.g., LOGIT_TRACE_TO) that explicitly target it using the logger's index. It will not process logs from general log macros (e.g., LOGIT_TRACE). |
Definition at line 40 of file Logger.hpp.
|
inline |
Retrieves a floating-point parameter from a logger.
logger_index | Index of logger. |
param | Logger parameter to retrieve. |
Definition at line 185 of file Logger.hpp.
|
inlinestatic |
Retrieves singleton instance of Logger.
Definition at line 29 of file Logger.hpp.
|
inline |
Retrieves an integer parameter from a logger.
logger_index | Index of logger. |
param | Logger parameter to retrieve. |
Definition at line 172 of file Logger.hpp.
|
inline |
Retrieves a string parameter from a logger.
logger_index | Index of logger. |
param | Logger parameter to retrieve. |
Definition at line 159 of file Logger.hpp.
|
inline |
Checks if a logger is enabled.
logger_index | Index of logger. |
Definition at line 68 of file Logger.hpp.
|
inline |
Checks whether a logger is in single mode.
logger_index | Index of logger. |
Definition at line 122 of file Logger.hpp.
|
inline |
Logs a LogRecord using added loggers and formatters.
Formats the log message using each logger's corresponding formatter and sends the formatted message to the logger.
record | Log record to be logged. |
Definition at line 136 of file Logger.hpp.
|
inline |
Logs message without arguments and returns empty tuple.
record | Log record. |
Definition at line 221 of file Logger.hpp.
|
inline |
Logs message and returns argument.
Logs provided argument and returns it.
T | Type of argument. |
record | Log record. |
args | Argument to be logged. |
Definition at line 213 of file Logger.hpp.
|
inline |
Logs message and returns tuple of arguments.
Ts | Types of arguments. |
record | Log record. |
args | Arguments to be logged. |
Definition at line 200 of file Logger.hpp.
|
inlinestaticprivate |
Atexit shutdown handler for Logger and TaskExecutor.
Called automatically at program exit.
Definition at line 306 of file Logger.hpp.
|
inlineprivate |
Definition at line 261 of file Logger.hpp.
|
inlineprivate |
Logs a record with given arguments.
Ts | Types of arguments. |
record | Log record. |
args | Arguments to be logged. |
Definition at line 275 of file Logger.hpp.
|
inline |
Sets minimal log level for a specific logger.
logger_index | Index of logger. |
level | Minimum log level. |
Definition at line 111 of file Logger.hpp.
|
inline |
Sets minimal log level for all loggers.
level | Minimum log level. |
Definition at line 100 of file Logger.hpp.
|
inline |
Enables or disables a logger by index.
logger_index | Index of logger. |
enabled | True to enable, false to disable. |
Definition at line 57 of file Logger.hpp.
|
inline |
Sets single-mode flag for a logger.
logger_index | Index of logger to modify. |
single_mode | True to enable single mode, false to disable. |
Definition at line 79 of file Logger.hpp.
|
inline |
Sets timestamp offset for a specific logger.
logger_index | Index of logger to modify. |
offset_ms | Offset in milliseconds. |
Definition at line 90 of file Logger.hpp.
|
inline |
Shuts down logger system.
Disables further logging, waits for asynchronous tasks to complete, and shuts down TaskExecutor.
Definition at line 239 of file Logger.hpp.
|
inline |
Waits for all asynchronous loggers to finish processing.
Ensures that all log messages are fully processed before continuing.
Definition at line 229 of file Logger.hpp.
|
private |
Container for logger-formatter pairs.
Definition at line 257 of file Logger.hpp.
|
mutableprivate |
Mutex for thread safety during logging operations.
Definition at line 258 of file Logger.hpp.
|
private |
Flag indicating if shutdown was requested.
Definition at line 259 of file Logger.hpp.