A logger base class for handling different levels of log messages. More...
#include <communicator.hpp>
Public Types | |
| enum class | LOG_LEVEL : std::uint32_t { NONE = 0 , PRINT , WARN , INFO , DEBUG , TRACE } |
| Log verbosity levels. More... | |
Public Member Functions | |
| Logger (Communicator *comm, config::Options options) | |
| Construct a new logger. More... | |
| LOG_LEVEL | verbosity_level () const |
| Get the verbosity level of the logger. More... | |
| template<typename... Args> | |
| void | log (LOG_LEVEL level, Args const &... args) |
| Logs a message using the specified verbosity level. More... | |
| template<typename... Args> | |
| void | print (Args const &... args) |
| Logs a print message. More... | |
| template<typename... Args> | |
| void | warn (Args const &... args) |
| Logs a warning message. More... | |
| template<typename... Args> | |
| void | info (Args const &... args) |
| Logs an informational message. More... | |
| template<typename... Args> | |
| void | debug (Args const &... args) |
| Logs a debug message. More... | |
| template<typename... Args> | |
| void | trace (Args const &... args) |
| Logs a trace message. More... | |
Static Public Member Functions | |
| static constexpr const char * | level_name (LOG_LEVEL level) |
| Get the string name of a log level. More... | |
Static Public Attributes | |
| static constexpr std::array< char const *, 6 > | LOG_LEVEL_NAMES |
| Log level names corresponding to the LOG_LEVEL enum. More... | |
Protected Member Functions | |
| virtual std::uint32_t | get_thread_id () |
| Returns a unique thread ID for the current thread. More... | |
| virtual void | do_log (LOG_LEVEL level, std::ostringstream &&ss) |
| Handles the logging of a messages. More... | |
| Communicator * | get_communicator () const |
| Get the communicator used by the logger. More... | |
A logger base class for handling different levels of log messages.
The logger class provides various logging methods with different verbosity levels. It ensures thread-safety using a mutex and allows filtering of log messages based on the configured verbosity level.
TODO: support writing to a file.
Definition at line 173 of file communicator.hpp.
|
strong |
Log verbosity levels.
Defines different logging levels for filtering messages.
| Enumerator | |
|---|---|
| NONE | No logging. |
General print messages. | |
| WARN | Warning messages. |
| INFO | Informational messages. |
| DEBUG | Debug messages. |
| TRACE | Trace messages. |
Definition at line 180 of file communicator.hpp.
| rapidsmpf::Communicator::Logger::Logger | ( | Communicator * | comm, |
| config::Options | options | ||
| ) |
Construct a new logger.
To control the verbosity level, set the configuration option "log" to one of following:
| comm | The Communicator to use. |
| options | Configuration options. |
|
inline |
Logs a debug message.
| Args | Types of the message components. |
| args | The components of the message to log. |
Definition at line 293 of file communicator.hpp.
|
inlineprotectedvirtual |
Handles the logging of a messages.
This base implementation prepend the rank and thread id to the message and print it to std::cout.
Override this method in a derived classes to customize logging behavior.
| level | The verbosity level of the message. |
| ss | The formatted message as a string stream. |
Definition at line 337 of file communicator.hpp.
|
inlineprotected |
Get the communicator used by the logger.
Definition at line 350 of file communicator.hpp.
|
inlineprotectedvirtual |
Returns a unique thread ID for the current thread.
Definition at line 314 of file communicator.hpp.
|
inline |
Logs an informational message.
| Args | Types of the message components. |
| args | The components of the message to log. |
Definition at line 282 of file communicator.hpp.
|
inlinestaticconstexpr |
Get the string name of a log level.
| level | The log level. |
Definition at line 202 of file communicator.hpp.
|
inline |
Logs a message using the specified verbosity level.
Formats and outputs a message if the verbosity level is high enough.
| Args | Types of the message components, must support the << operator. |
| level | The verbosity level of the message. |
| args | The components of the message to log. |
Definition at line 244 of file communicator.hpp.
|
inline |
Logs a print message.
| Args | Types of the message components. |
| args | The components of the message to log. |
Definition at line 260 of file communicator.hpp.
|
inline |
Logs a trace message.
| Args | Types of the message components. |
| args | The components of the message to log. |
Definition at line 304 of file communicator.hpp.
|
inline |
Get the verbosity level of the logger.
Definition at line 230 of file communicator.hpp.
|
inline |
Logs a warning message.
| Args | Types of the message components. |
| args | The components of the message to log. |
Definition at line 271 of file communicator.hpp.
|
staticconstexpr |
Log level names corresponding to the LOG_LEVEL enum.
Definition at line 192 of file communicator.hpp.