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

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...
 
Communicatorget_communicator () const
 Get the communicator used by the logger. 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.

TODO: support writing to a file.

Definition at line 173 of file communicator.hpp.

Member Enumeration Documentation

◆ LOG_LEVEL

enum rapidsmpf::Communicator::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 180 of file communicator.hpp.

Constructor & Destructor Documentation

◆ Logger()

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:

  • NONE: No logging.
  • PRINT: General print messages.
  • WARN: Warning messages (default)
  • INFO: Informational messages.
  • DEBUG: Debug messages.
  • TRACE: Trace messages.
Parameters
commThe Communicator to use.
optionsConfiguration options.

Member Function Documentation

◆ debug()

template<typename... Args>
void rapidsmpf::Communicator::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 293 of file communicator.hpp.

◆ do_log()

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

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

Definition at line 337 of file communicator.hpp.

◆ get_communicator()

Communicator* rapidsmpf::Communicator::Logger::get_communicator ( ) const
inlineprotected

Get the communicator used by the logger.

Returns
Pointer to the Communicator instance.

Definition at line 350 of file communicator.hpp.

◆ get_thread_id()

virtual std::uint32_t rapidsmpf::Communicator::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 314 of file communicator.hpp.

◆ info()

template<typename... Args>
void rapidsmpf::Communicator::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 282 of file communicator.hpp.

◆ level_name()

static constexpr const char* rapidsmpf::Communicator::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 202 of file communicator.hpp.

◆ log()

template<typename... Args>
void rapidsmpf::Communicator::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 244 of file communicator.hpp.

◆ print()

template<typename... Args>
void rapidsmpf::Communicator::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 260 of file communicator.hpp.

◆ trace()

template<typename... Args>
void rapidsmpf::Communicator::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 304 of file communicator.hpp.

◆ verbosity_level()

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

Get the verbosity level of the logger.

Returns
The verbosity level.

Definition at line 230 of file communicator.hpp.

◆ warn()

template<typename... Args>
void rapidsmpf::Communicator::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 271 of file communicator.hpp.

Member Data Documentation

◆ LOG_LEVEL_NAMES

constexpr std::array<char const*, 6> rapidsmpf::Communicator::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 192 of file communicator.hpp.


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