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 bool single_mode =
false) {
51 std::lock_guard<std::mutex> lock(
m_mutex);
64 std::lock_guard<std::mutex> lock(
m_mutex);
65 if (logger_index >= 0 && logger_index <
static_cast<int>(
m_loggers.size())) {
66 m_loggers[logger_index].enabled = enabled;
74 std::lock_guard<std::mutex> lock(
m_mutex);
75 if (logger_index >= 0 && logger_index <
static_cast<int>(
m_loggers.size())) {
85 std::lock_guard<std::mutex> lock(
m_mutex);
86 if (logger_index >= 0 && logger_index <
static_cast<int>(
m_loggers.size())) {
87 m_loggers[logger_index].single_mode = single_mode;
95 std::lock_guard<std::mutex> lock(
m_mutex);
96 if (logger_index >= 0 && logger_index <
static_cast<int>(
m_loggers.size())) {
97 return m_loggers[logger_index].single_mode;
109 std::lock_guard<std::mutex> lock(
m_mutex);
113 strategy.logger->log(record, strategy.formatter->
format(record));
117 if (strategy.single_mode)
continue;
118 strategy.logger->log(record, strategy.formatter->
format(record));
127 if (logger_index >= 0 && logger_index <
static_cast<int>(
m_loggers.size())) {
128 const auto& strategy =
m_loggers[logger_index];
129 return strategy.logger->get_string_param(param);
131 return std::string();
139 if (logger_index >= 0 && logger_index <
static_cast<int>(
m_loggers.size())) {
140 const auto& strategy =
m_loggers[logger_index];
141 return strategy.logger->get_int_param(param);
151 if (logger_index >= 0 && logger_index <
static_cast<int>(
m_loggers.size())) {
152 const auto& strategy =
m_loggers[logger_index];
153 return strategy.logger->get_float_param(param);
163 template <
typename... Ts>
165 this->
print(record, args...);
166 return std::forward_as_tuple(std::forward<Ts>(args)...);
174 template <
typename T>
176 this->
print(record, arg);
177 return std::forward<decltype(arg)>(arg);
206 template <
typename... Ts>
208 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 set_logger_enabled(int logger_index, bool enabled)
Enables or disables a logger by index.
void wait()
Waits for all asynchronous loggers to finish processing.
void log(const LogRecord &record)
Logs a LogRecord using all added loggers and formatters.
void set_logger_single_mode(int logger_index, bool single_mode)
Sets the single-mode flag for a logger.
void add_logger(std::unique_ptr< ILogger > logger, std::unique_ptr< ILogFormatter > formatter, bool single_mode=false)
Adds a logger and its corresponding formatter.
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.
bool is_logger_single_mode(int logger_index) const
Checks whether a logger is in single mode.
double get_float_param(int logger_index, const LoggerParam ¶m) const
Retrieves a floating-point parameter from the logger.
std::string get_string_param(int logger_index, const LoggerParam ¶m) const
Retrieves a string 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.
int64_t get_int_param(int logger_index, const LoggerParam ¶m) const
Retrieves an integer parameter from the logger.
bool is_logger_enabled(int logger_index) const
Checks whether a logger is enabled.
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.
bool enabled
Flag indicating if the logger is enabled.