2#ifndef _LOGIT_LOGGER_HPP_INCLUDED
3#define _LOGIT_LOGGER_HPP_INCLUDED
37 strategy.logger->wait();
48 std::unique_ptr<ILogger> logger,
49 std::unique_ptr<ILogFormatter> formatter,
50 const bool& single_mode =
false) {
51 std::lock_guard<std::mutex> lock(
m_mutex);
62 std::lock_guard<std::mutex> lock(
m_mutex);
66 strategy.logger->log(record, strategy.formatter->
format(record));
70 if (strategy.single_mode)
continue;
71 strategy.logger->log(record, strategy.formatter->
format(record));
80 if (logger_index >= 0 && logger_index <
static_cast<int>(
m_loggers.size())) {
81 const auto& strategy =
m_loggers[logger_index];
82 return strategy.logger->get_string_param(param);
92 if (logger_index >= 0 && logger_index <
static_cast<int>(
m_loggers.size())) {
93 const auto& strategy =
m_loggers[logger_index];
94 return strategy.logger->get_int_param(param);
104 if (logger_index >= 0 && logger_index <
static_cast<int>(
m_loggers.size())) {
105 const auto& strategy =
m_loggers[logger_index];
106 return strategy.logger->get_float_param(param);
116 template <
typename... Ts>
118 this->
print(record, args...);
119 return std::forward_as_tuple(std::forward<Ts>(args)...);
127 template <
typename T>
129 this->
print(record, arg);
130 return std::forward<decltype(arg)>(arg);
158 template <
typename... Ts>
160 if (
sizeof...(Ts) == 0) {
Defines the interface for loggers used in the logging system.
Singleton class that manages multiple loggers and formatters.
auto log_and_return(const LogRecord &record) -> std::tuple<>
Logs a message without arguments and returns an empty tuple.
void wait()
Waits for all asynchronous loggers to finish processing.
void log(const LogRecord &record)
Logs a LogRecord using all added loggers and formatters.
Logger & operator=(const Logger &)=delete
Logger(const Logger &)=delete
std::vector< LoggerStrategy > m_loggers
Container for logger-formatter pairs.
auto log_and_return(const LogRecord &record, T &&arg) -> decltype(arg)
Logs the message and returns a single argument.
std::mutex m_mutex
Mutex for thread safety during logging operations.
double get_float_param(const int &logger_index, const LoggerParam ¶m) const
Retrieves a floating-point parameter from the logger.
void add_logger(std::unique_ptr< ILogger > logger, std::unique_ptr< ILogFormatter > formatter, const bool &single_mode=false)
Adds a logger and its corresponding formatter.
int64_t get_int_param(const int &logger_index, const LoggerParam ¶m) const
Retrieves an integer parameter from the logger.
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.
std::string get_string_param(const int &logger_index, const LoggerParam ¶m) const
Retrieves a string parameter from the logger.
static Logger & get_instance()
Retrieves the singleton instance of Logger.
Logger & operator=(Logger &&)=delete
void print(const LogRecord &record, Ts const &... args)
Logs a record with the given arguments.
The primary namespace for the LogIt++ library.
std::vector< std::string > split_arguments(const std::string &all_names)
Splits a string of argument names into individual names, ignoring nested templates,...
LoggerParam
Enumeration for different logger parameters that can be retrieved.
std::vector< VariableValue > args_to_array(std::vector< std::string >::const_iterator name_iter)
Base case of recursion for argument conversion — when there are no more arguments.
Stores log metadata and content.
const int logger_index
Logger index (-1 to log to all).
const std::string format
Format string for the message.
std::vector< VariableValue > args_array
Argument values for the log.
const std::string arg_names
Argument names for the log.
Structure to hold a logger-formatter pair.
std::unique_ptr< ILogger > logger
The logger instance.
bool single_mode
Flag indicating if the logger is in single mode.
std::unique_ptr< ILogFormatter > formatter
The formatter instance.