maliput
Logger Class Reference

Detailed Description

A logger class implementation.

Logger will dump all messages to a sink (SinkBase) which will be in charge of serializing the messages to the appropriate channel. By default, Sink implementation is used.

It provides six different log levels, logger::level , which can be filtered based on the severity of the message.

Comments about the design:

  • Type-erasure is used to hide the implementation of the format method. This was initially done due to the fact that the logger was using the fmt library, but it was later removed however the design was kept for future use and to avoid ABI breakage.
  • Within Logger::log() method the variadic arguments are unpacked and serialized using a functor Serialize . The alternative to the functor is to use a lambda expresion, but there is a bug in gcc that is not fixed until 8.1 version.
    See also
    GCC bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85305.
  • Another way to do type-erasure is using std::any to allocate the variadic arguments, but this idea was dismissed given that it wouldn't allow the logger to manage all kind of types, due to the fact that an overload of any_cast<T>() for each new type to be serialized would be required.

#include <include/maliput/common/logger.h>

Public Member Functions

 MALIPUT_NO_COPY_NO_MOVE_NO_ASSIGN (Logger)
 
 Logger ()=default
 
template<typename... Args>
void trace (const Args &... args)
 Log the message showing trace level prefix. More...
 
template<typename... Args>
void debug (const Args &... args)
 Log the message showing debug level prefix. More...
 
template<typename... Args>
void info (const Args &... args)
 Log the message showing info level prefix. More...
 
template<typename... Args>
void warn (const Args &... args)
 Log the message showing warning level prefix. More...
 
template<typename... Args>
void error (const Args &... args)
 Log the message showing error level prefix. More...
 
template<typename... Args>
void critical (const Args &... args)
 Log the message showing critical level prefix. More...
 
void set_sink (std::unique_ptr< common::SinkBase > sink)
 Set a sink. More...
 
SinkBaseget_sink ()
 Get the current sink. More...
 
std::string set_level (logger::level log_level)
 Sets the minimum level of messages to be logged. More...
 

Static Public Attributes

static constexpr int kNumberOfArguments {100}
 Indicates the maximum number of arguments that a single log command is able to process. More...
 

Related Functions

(Note that these are not member functions.)

std::string set_log_level (const std::string &level)
 Invokes maliput::log()->set_level(level). More...
 
common::Loggerlog ()
 Retrieve an instance of a logger to use for logger. More...
 

Constructor & Destructor Documentation

◆ Logger()

Logger ( )
default

Member Function Documentation

◆ get_sink()

SinkBase* get_sink ( )

Get the current sink.

Returns
A pointer to the current sink.

◆ MALIPUT_NO_COPY_NO_MOVE_NO_ASSIGN()

MALIPUT_NO_COPY_NO_MOVE_NO_ASSIGN ( Logger  )

◆ set_level()

std::string set_level ( logger::level  log_level)

Sets the minimum level of messages to be logged.

Parameters
log_levelMust be a level enum value from the level enumerations: trace, debug, info, warning, error, critical or off.
Returns
The string value of the previous log level.
See also
logger::kLevelToString.

◆ set_sink()

void set_sink ( std::unique_ptr< common::SinkBase sink)

Set a sink.

Parameters
sinkIs a SinkBase implementation.
Exceptions
common::assertion_errorWhen sink is nullptr.

Friends And Related Function Documentation

◆ log()

common::Logger * log ( )
related

Retrieve an instance of a logger to use for logger.

See Logger.

◆ set_log_level()

std::string set_log_level ( const std::string &  level)
related

Invokes maliput::log()->set_level(level).

See Logger.

Parameters
levelMust be a string from the level enumerations: trace, debug, info, warning, error, critical or off.
Returns
The string value of the previous log level.
Exceptions
std::out_of_rangeWhen level is not one of the predefined values.

Member Data Documentation

◆ kNumberOfArguments

constexpr int kNumberOfArguments {100}
staticconstexpr

Indicates the maximum number of arguments that a single log command is able to process.


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