![]() |
LogIt++
|
Outputs log messages to the console with optional ANSI color support. More...
#include <ConsoleLogger.hpp>
Classes | |
struct | Config |
Configuration for the console logger. More... | |
Public Member Functions | |
ConsoleLogger () | |
Default constructor that uses default configuration. | |
ConsoleLogger (const Config &config) | |
Constructor with custom configuration. | |
ConsoleLogger (const bool async) | |
Constructor with asynchronous flag. | |
virtual | ~ConsoleLogger ()=default |
void | set_config (const Config &config) |
Sets the logger configuration. | |
Config | get_config () |
Gets the current logger configuration. | |
void | log (const LogRecord &record, const std::string &message) override |
Logs a message to the console with thread safety. | |
std::string | get_string_param (const LoggerParam ¶m) const override |
Retrieves a string parameter from the logger. | |
int64_t | get_int_param (const LoggerParam ¶m) const override |
Retrieves an integer parameter from the logger. | |
double | get_float_param (const LoggerParam ¶m) const override |
Retrieves a floating-point parameter from the logger. | |
void | set_log_level (LogLevel level) override |
Sets the minimal log level for this logger. | |
LogLevel | get_log_level () const override |
Gets the minimal log level for this logger. | |
void | wait () override |
Waits for all asynchronous tasks to complete. | |
![]() | |
virtual | ~ILogger ()=default |
Private Member Functions | |
void | reset_color () |
Resets the console text color to the default. | |
int64_t | get_last_log_ts () const |
Retrieves the timestamp of the last log. | |
int64_t | get_time_since_last_log () const |
Retrieves the time since the last log. | |
Private Attributes | |
std::mutex | m_mutex |
Mutex to protect console output. | |
Config | m_config |
Configuration for the console logger. | |
std::atomic< int64_t > | m_last_log_ts = ATOMIC_VAR_INIT(0) |
std::atomic< int > | m_log_level = ATOMIC_VAR_INIT(static_cast<int>(LogLevel::LOG_LVL_TRACE)) |
Outputs log messages to the console with optional ANSI color support.
This logger supports synchronous and asynchronous logging. It also handles platform-specific differences in handling colored console output.
Key Features:
Definition at line 32 of file ConsoleLogger.hpp.
|
inline |
Default constructor that uses default configuration.
Definition at line 47 of file ConsoleLogger.hpp.
|
inline |
Constructor with custom configuration.
config | The configuration for the logger. |
Definition at line 53 of file ConsoleLogger.hpp.
|
inline |
Constructor with asynchronous flag.
async | Boolean flag for asynchronous logging. |
Definition at line 59 of file ConsoleLogger.hpp.
|
virtualdefault |
|
inline |
Gets the current logger configuration.
Returns the logger's configuration with thread safety ensured.
Definition at line 77 of file ConsoleLogger.hpp.
|
inlineoverridevirtual |
Retrieves a floating-point parameter from the logger.
param | The parameter type to retrieve. |
Implements logit::ILogger.
Definition at line 154 of file ConsoleLogger.hpp.
|
inlineoverridevirtual |
Retrieves an integer parameter from the logger.
param | The parameter type to retrieve. |
Implements logit::ILogger.
Definition at line 141 of file ConsoleLogger.hpp.
|
inlineprivate |
Retrieves the timestamp of the last log.
Definition at line 401 of file ConsoleLogger.hpp.
|
inlineoverridevirtual |
Gets the minimal log level for this logger.
Implements logit::ILogger.
Definition at line 170 of file ConsoleLogger.hpp.
|
inlineoverridevirtual |
Retrieves a string parameter from the logger.
This function does not return parameters related to file-based loggers, such as LastFileName
and LastFilePath
.
param | The parameter type to retrieve. |
Implements logit::ILogger.
Definition at line 128 of file ConsoleLogger.hpp.
|
inlineprivate |
Retrieves the time since the last log.
Definition at line 407 of file ConsoleLogger.hpp.
|
inlineoverridevirtual |
Logs a message to the console with thread safety.
If asynchronous logging is enabled, the message is added to the task queue; otherwise, it is logged directly.
record | The log record containing log information. |
message | The formatted log message. |
Implements logit::ILogger.
Definition at line 89 of file ConsoleLogger.hpp.
|
inlineprivate |
Resets the console text color to the default.
Definition at line 388 of file ConsoleLogger.hpp.
|
inline |
Sets the logger configuration.
This method sets the logger's configuration and ensures thread safety with a mutex lock.
config | The new configuration. |
Definition at line 69 of file ConsoleLogger.hpp.
|
inlineoverridevirtual |
Sets the minimal log level for this logger.
Implements logit::ILogger.
Definition at line 165 of file ConsoleLogger.hpp.
|
inlineoverridevirtual |
Waits for all asynchronous tasks to complete.
If asynchronous logging is enabled, waits for all pending log messages to be written.
Implements logit::ILogger.
Definition at line 176 of file ConsoleLogger.hpp.
|
private |
Configuration for the console logger.
Definition at line 190 of file ConsoleLogger.hpp.
|
private |
Definition at line 191 of file ConsoleLogger.hpp.
|
private |
Definition at line 192 of file ConsoleLogger.hpp.
|
mutableprivate |
Mutex to protect console output.
Definition at line 189 of file ConsoleLogger.hpp.