LogIt++
|
Singleton class that manages multiple loggers and formatters. More...
#include <Logger.hpp>
Classes | |
struct | LoggerStrategy |
Structure to hold a logger-formatter pair. More... | |
Public Member Functions | |
void | wait () |
Waits for all asynchronous loggers to finish processing. | |
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 whether a logger is enabled. | |
void | set_logger_single_mode (int logger_index, bool single_mode) |
Sets the single-mode flag for a 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 all added loggers and formatters. | |
std::string | get_string_param (int logger_index, const LoggerParam ¶m) const |
Retrieves a string parameter from the logger. | |
int64_t | get_int_param (int logger_index, const LoggerParam ¶m) const |
Retrieves an integer parameter from the logger. | |
double | get_float_param (int logger_index, const LoggerParam ¶m) const |
Retrieves a floating-point parameter from the logger. | |
template<typename... Ts> | |
auto | log_and_return (const LogRecord &record, Ts &&... args) -> decltype(std::forward_as_tuple(std::forward< Ts >(args)...)) |
Logs the message and returns a tuple of arguments. | |
template<typename T > | |
auto | log_and_return (const LogRecord &record, T &&arg) -> decltype(arg) |
Logs the message and returns a single argument. | |
auto | log_and_return (const LogRecord &record) -> std::tuple<> |
Logs a message without arguments and returns an empty tuple. | |
Static Public Member Functions | |
static Logger & | get_instance () |
Retrieves the singleton instance of Logger . | |
Private Member Functions | |
template<typename... Ts> | |
void | print (const LogRecord &record, Ts const &... args) |
Logs a record with the given arguments. | |
Logger ()=default | |
~Logger () | |
Logger (const Logger &)=delete | |
Logger & | operator= (const Logger &)=delete |
Logger (Logger &&)=delete | |
Logger & | operator= (Logger &&)=delete |
Private Attributes | |
std::vector< LoggerStrategy > | m_loggers |
Container for logger-formatter pairs. | |
std::mutex | m_mutex |
Mutex for thread safety during logging operations. | |
Singleton class that manages multiple loggers and formatters.
The Logger
class allows adding multiple logger and formatter pairs (strategies) and provides methods to log messages using these strategies. It supports both synchronous and asynchronous logging. The class is thread-safe.
Definition at line 21 of file Logger.hpp.
|
privatedefault |
|
inlineprivate |
Definition at line 220 of file Logger.hpp.
|
privatedelete |
|
privatedelete |
|
inline |
Adds a logger and its corresponding formatter.
logger | A unique pointer to the logger instance. |
formatter | A unique pointer to the 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 47 of file Logger.hpp.
|
inline |
Retrieves a floating-point parameter from the logger.
logger_index | The index of the logger. |
param | The logger parameter to retrieve. |
Definition at line 150 of file Logger.hpp.
|
inlinestatic |
Retrieves the singleton instance of Logger
.
Logger
class. Definition at line 26 of file Logger.hpp.
|
inline |
Retrieves an integer parameter from the logger.
logger_index | The index of the logger. |
param | The logger parameter to retrieve. |
Definition at line 138 of file Logger.hpp.
|
inline |
Retrieves a string parameter from the logger.
logger_index | The index of the logger. |
param | The logger parameter to retrieve. |
Definition at line 126 of file Logger.hpp.
|
inline |
Checks whether a logger is enabled.
logger_index | The index of the logger to check. |
Definition at line 73 of file Logger.hpp.
|
inline |
Checks whether a logger is in single mode.
logger_index | The index of the logger. |
Definition at line 94 of file Logger.hpp.
|
inline |
Logs a LogRecord
using all added loggers and formatters.
The log()
method formats the log message using each logger's corresponding formatter and sends the formatted message to each logger.
record | The log record to be logged. |
Definition at line 108 of file Logger.hpp.
|
inline |
Logs a message without arguments and returns an empty tuple.
record | The log record. |
Definition at line 183 of file Logger.hpp.
|
inline |
Logs the message and returns a single argument.
T | Type of the argument. |
record | The log record. |
arg | The argument to be logged. |
Definition at line 175 of file Logger.hpp.
|
inline |
Logs the message and returns a tuple of arguments.
Ts | Types of the arguments. |
record | The log record. |
args | The arguments to be logged. |
Definition at line 164 of file Logger.hpp.
|
inlineprivate |
Logs a record with the given arguments.
Ts | Types of the arguments. |
record | The log record. |
args | The arguments to be logged. |
Definition at line 207 of file Logger.hpp.
|
inline |
Enables or disables a logger by index.
logger_index | The index of the logger to modify. |
enabled | True to enable the logger, false to disable it. |
Definition at line 63 of file Logger.hpp.
|
inline |
Sets the single-mode flag for a logger.
logger_index | The index of the logger. |
single_mode | True to set the logger to single mode, false otherwise. |
Definition at line 84 of file Logger.hpp.
|
inline |
Waits for all asynchronous loggers to finish processing.
This method ensures that all log messages are fully processed before continuing. It calls the wait()
function of each logger.
Definition at line 35 of file Logger.hpp.
|
private |
Container for logger-formatter pairs.
Definition at line 199 of file Logger.hpp.
|
mutableprivate |
Mutex for thread safety during logging operations.
Definition at line 200 of file Logger.hpp.