Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | List of all members
rapidsmpf::Logger Class Reference

A logger base class for handling different levels of log messages. More...

#include <logger.hpp>

Inheritance diagram for rapidsmpf::Logger:

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
 
Loggeroperator= (Logger const &)=delete
 
 Logger (Logger &&)=delete
 
Loggeroperator= (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< Loggercreate (LOG_LEVEL level=LOG_LEVEL::WARN, std::string name="unknown")
 Create a logger. More...
 
static std::shared_ptr< Loggerfrom_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...
 

Detailed Description

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.

Member Enumeration Documentation

◆ LOG_LEVEL

enum rapidsmpf::Logger::LOG_LEVEL : std::uint32_t
strong

Log verbosity levels.

Defines different logging levels for filtering messages.

Enumerator
NONE 

No logging.

PRINT 

General print messages.

WARN 

Warning messages.

INFO 

Informational messages.

DEBUG 

Debug messages.

TRACE 

Trace messages.

Definition at line 44 of file logger.hpp.

Constructor & Destructor Documentation

◆ Logger()

rapidsmpf::Logger::Logger ( LOG_LEVEL  level,
std::string  name 
)
protected

Constructs a logger.

Parameters
levelThe verbosity level.
nameThe logger name.

Member Function Documentation

◆ create()

static std::shared_ptr<Logger> rapidsmpf::Logger::create ( LOG_LEVEL  level = LOG_LEVEL::WARN,
std::string  name = "unknown" 
)
static

Create a logger.

Parameters
levelThe verbosity level (defaults to LOG_LEVEL::WARN).
nameThe logger name (defaults to "unknown").
Returns
A shared pointer to the newly constructed logger.

◆ debug()

template<typename... Args>
void rapidsmpf::Logger::debug ( Args const &...  args)
inline

Logs a debug message.

Template Parameters
ArgsTypes of the message components.
Parameters
argsThe components of the message to log.

Definition at line 192 of file logger.hpp.

◆ do_log()

virtual void rapidsmpf::Logger::do_log ( LOG_LEVEL  level,
std::ostringstream &&  ss 
)
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.

Parameters
levelThe verbosity level of the message.
ssThe formatted message as a string stream.

Definition at line 243 of file logger.hpp.

◆ from_options()

static std::shared_ptr<Logger> rapidsmpf::Logger::from_options ( config::Options  options)
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:

  • NONE: No logging.
  • PRINT: General print messages.
  • WARN: Warning messages (default)
  • INFO: Informational messages.
  • DEBUG: Debug messages.
  • TRACE: Trace messages.
Parameters
optionsConfiguration options.
Returns
A shared pointer to the newly constructed logger.

◆ get_thread_id()

virtual std::uint32_t rapidsmpf::Logger::get_thread_id ( )
inlineprotectedvirtual

Returns a unique thread ID for the current thread.

Returns
A unique ID for the current thread.

Definition at line 220 of file logger.hpp.

◆ info()

template<typename... Args>
void rapidsmpf::Logger::info ( Args const &...  args)
inline

Logs an informational message.

Template Parameters
ArgsTypes of the message components.
Parameters
argsThe components of the message to log.

Definition at line 181 of file logger.hpp.

◆ level_name()

static constexpr char const* rapidsmpf::Logger::level_name ( LOG_LEVEL  level)
inlinestaticconstexpr

Get the string name of a log level.

Parameters
levelThe log level.
Returns
The corresponding log level name or "UNKNOWN" if out of range.

Definition at line 66 of file logger.hpp.

◆ log()

template<typename... Args>
void rapidsmpf::Logger::log ( LOG_LEVEL  level,
Args const &...  args 
)
inline

Logs a message using the specified verbosity level.

Formats and outputs a message if the verbosity level is high enough.

Template Parameters
ArgsTypes of the message components, must support the << operator.
Parameters
levelThe verbosity level of the message.
argsThe components of the message to log.

Definition at line 143 of file logger.hpp.

◆ print()

template<typename... Args>
void rapidsmpf::Logger::print ( Args const &...  args)
inline

Logs a print message.

Template Parameters
ArgsTypes of the message components.
Parameters
argsThe components of the message to log.

Definition at line 159 of file logger.hpp.

◆ set_name()

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.

Parameters
nameThe new name.

◆ trace()

template<typename... Args>
void rapidsmpf::Logger::trace ( Args const &...  args)
inline

Logs a trace message.

Template Parameters
ArgsTypes of the message components.
Parameters
argsThe components of the message to log.

Definition at line 203 of file logger.hpp.

◆ verbosity_level()

LOG_LEVEL rapidsmpf::Logger::verbosity_level ( ) const
inline

Get the verbosity level of the logger.

Returns
The verbosity level.

Definition at line 118 of file logger.hpp.

◆ warn()

template<typename... Args>
void rapidsmpf::Logger::warn ( Args const &...  args)
inline

Logs a warning message.

Template Parameters
ArgsTypes of the message components.
Parameters
argsThe components of the message to log.

Definition at line 170 of file logger.hpp.

Member Data Documentation

◆ LOG_LEVEL_NAMES

constexpr std::array<char const*, 6> rapidsmpf::Logger::LOG_LEVEL_NAMES
staticconstexpr
Initial value:
{
"NONE", "PRINT", "WARN", "INFO", "DEBUG", "TRACE"
}

Log level names corresponding to the LOG_LEVEL enum.

Definition at line 56 of file logger.hpp.


The documentation for this class was generated from the following file: