A logger base class for handling different levels of log messages. More...
#include <logger.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 (Logger const &)=delete | |
| Logger & | operator= (Logger const &)=delete |
| Logger (Logger &&)=delete | |
| Logger & | operator= (Logger &&)=delete |
| LOG_LEVEL | verbosity_level () const |
| Get the verbosity level of the logger. More... | |
| void | set_name (std::string name) |
| Update the name used in log message prefixes. 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 char const * | level_name (LOG_LEVEL level) |
| Get the string name of a log level. More... | |
| static std::shared_ptr< Logger > | create (LOG_LEVEL level=LOG_LEVEL::WARN, std::string name="unknown") |
| Create a logger. More... | |
| static std::shared_ptr< Logger > | from_options (config::Options options) |
| Create a logger from configuration options. 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 | |
| Logger (LOG_LEVEL level, std::string name) | |
| Constructs a logger. More... | |
| 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... | |
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.
The name used in log message prefixes can either be supplied at construction time or set later via set_name(). The latter supports communicators (such as UCXX) where the identifying name (e.g. the rank) is only known after a bootstrap handshake.
TODO: support writing to a file.
Definition at line 37 of file logger.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 44 of file logger.hpp.
|
protected |
Constructs a logger.
| level | The verbosity level. |
| name | The logger name. |
|
static |
Create a logger.
| level | The verbosity level (defaults to LOG_LEVEL::WARN). |
| name | The logger name (defaults to "unknown"). |
|
inline |
Logs a debug message.
| Args | Types of the message components. |
| args | The components of the message to log. |
Definition at line 192 of file logger.hpp.
|
inlineprotectedvirtual |
Handles the logging of a messages.
This base implementation prepend the name 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 243 of file logger.hpp.
|
static |
Create a logger from configuration options.
The name defaults to "unknown" and may be updated later via set_name(). This is intended for bootstrap scenarios where the identifying name is only known after a network handshake but logging may already be required.
To control the verbosity level, set the configuration option "log" to one of following:
| options | Configuration options. |
|
inlineprotectedvirtual |
Returns a unique thread ID for the current thread.
Definition at line 220 of file logger.hpp.
|
inline |
Logs an informational message.
| Args | Types of the message components. |
| args | The components of the message to log. |
Definition at line 181 of file logger.hpp.
|
inlinestaticconstexpr |
Get the string name of a log level.
| level | The log level. |
Definition at line 66 of file logger.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 143 of file logger.hpp.
|
inline |
Logs a print message.
| Args | Types of the message components. |
| args | The components of the message to log. |
Definition at line 159 of file logger.hpp.
| void rapidsmpf::Logger::set_name | ( | std::string | name | ) |
Update the name used in log message prefixes.
Thread-safe (acquires the same mutex used to serialize log output). May be called any number of times. Concurrent log calls will observe either the old or the new value, never a partially written one.
| name | The new name. |
|
inline |
Logs a trace message.
| Args | Types of the message components. |
| args | The components of the message to log. |
Definition at line 203 of file logger.hpp.
|
inline |
Get the verbosity level of the logger.
Definition at line 118 of file logger.hpp.
|
inline |
Logs a warning message.
| Args | Types of the message components. |
| args | The components of the message to log. |
Definition at line 170 of file logger.hpp.
|
staticconstexpr |
Log level names corresponding to the LOG_LEVEL enum.
Definition at line 56 of file logger.hpp.