Logger that outputs log messages to the console with optional color coding.
More...
#include <ConsoleLogger.hpp>
|
| 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. This method sets the logger's configuration and ensures thread safety with a mutex lock.
|
|
Config | get_config () |
| Gets the current logger configuration. Returns the logger's configuration with thread safety ensured.
|
|
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 | wait () override |
| Waits for all asynchronous tasks to complete. If asynchronous logging is enabled, waits for all pending log messages to be written.
|
|
virtual | ~ILogger ()=default |
|
Logger that outputs log messages to the console with optional color coding.
The ConsoleLogger
provides synchronous or asynchronous logging to the console, with optional support for colored output based on ANSI codes. For Windows, it includes logic to handle ANSI color codes.
Definition at line 25 of file ConsoleLogger.hpp.
◆ ConsoleLogger() [1/3]
logit::ConsoleLogger::ConsoleLogger |
( |
| ) |
|
|
inline |
Default constructor that uses default configuration.
Definition at line 36 of file ConsoleLogger.hpp.
◆ ConsoleLogger() [2/3]
logit::ConsoleLogger::ConsoleLogger |
( |
const Config & | config | ) |
|
|
inline |
Constructor with custom configuration.
- Parameters
-
config | The configuration for the logger. |
Definition at line 42 of file ConsoleLogger.hpp.
◆ ConsoleLogger() [3/3]
logit::ConsoleLogger::ConsoleLogger |
( |
const bool | async | ) |
|
|
inline |
Constructor with asynchronous flag.
- Parameters
-
async | Boolean flag for asynchronous logging. |
Definition at line 48 of file ConsoleLogger.hpp.
◆ ~ConsoleLogger()
virtual logit::ConsoleLogger::~ConsoleLogger |
( |
| ) |
|
|
virtualdefault |
◆ get_config()
Config logit::ConsoleLogger::get_config |
( |
| ) |
|
|
inline |
Gets the current logger configuration. Returns the logger's configuration with thread safety ensured.
- Returns
- The current configuration.
Definition at line 66 of file ConsoleLogger.hpp.
◆ get_float_param()
double logit::ConsoleLogger::get_float_param |
( |
const LoggerParam & | param | ) |
const |
|
inlineoverridevirtual |
Retrieves a floating-point parameter from the logger.
- Parameters
-
param | The parameter type to retrieve. |
- Returns
- A double representing the requested parameter, or 0.0 if the parameter is unsupported.
Implements logit::ILogger.
Definition at line 137 of file ConsoleLogger.hpp.
◆ get_int_param()
int64_t logit::ConsoleLogger::get_int_param |
( |
const LoggerParam & | param | ) |
const |
|
inlineoverridevirtual |
Retrieves an integer parameter from the logger.
- Parameters
-
param | The parameter type to retrieve. |
- Returns
- An integer representing the requested parameter, or 0 if the parameter is unsupported.
Implements logit::ILogger.
Definition at line 124 of file ConsoleLogger.hpp.
◆ get_last_log_ts()
int64_t logit::ConsoleLogger::get_last_log_ts |
( |
| ) |
const |
|
inlineprivate |
Retrieves the timestamp of the last log.
- Returns
- The last log timestamp.
Definition at line 289 of file ConsoleLogger.hpp.
◆ get_string_param()
std::string logit::ConsoleLogger::get_string_param |
( |
const LoggerParam & | param | ) |
const |
|
inlineoverridevirtual |
Retrieves a string parameter from the logger.
This function does not return parameters related to file-based loggers, such as LastFileName
and LastFilePath
.
- Parameters
-
param | The parameter type to retrieve. |
- Returns
- A string representing the requested parameter, or an empty string if the parameter is unsupported.
Implements logit::ILogger.
Definition at line 111 of file ConsoleLogger.hpp.
◆ get_time_since_last_log()
int64_t logit::ConsoleLogger::get_time_since_last_log |
( |
| ) |
const |
|
inlineprivate |
Retrieves the time since the last log.
- Returns
- The time in milliseconds since the last log.
Definition at line 295 of file ConsoleLogger.hpp.
◆ log()
void logit::ConsoleLogger::log |
( |
const LogRecord & | record, |
|
|
const std::string & | message ) |
|
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.
- Parameters
-
record | The log record containing log information. |
message | The formatted log message. |
Implements logit::ILogger.
Definition at line 78 of file ConsoleLogger.hpp.
◆ reset_color()
void logit::ConsoleLogger::reset_color |
( |
| ) |
|
|
inlineprivate |
◆ set_config()
void logit::ConsoleLogger::set_config |
( |
const Config & | config | ) |
|
|
inline |
Sets the logger configuration. This method sets the logger's configuration and ensures thread safety with a mutex lock.
- Parameters
-
config | The new configuration. |
Definition at line 58 of file ConsoleLogger.hpp.
◆ wait()
void logit::ConsoleLogger::wait |
( |
| ) |
|
|
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 149 of file ConsoleLogger.hpp.
◆ m_config
Config logit::ConsoleLogger::m_config |
|
private |
◆ m_last_log_ts
std::atomic<int64_t> logit::ConsoleLogger::m_last_log_ts = ATOMIC_VAR_INIT(0) |
|
private |
◆ m_mutex
std::mutex logit::ConsoleLogger::m_mutex |
|
mutableprivate |
The documentation for this class was generated from the following file: