mrs_lib
Various reusable classes, functions and utilities for use in MRS projects
Loading...
Searching...
No Matches
mrs_lib::Logger Class Reference

Wrapper for rclcpp::Logger with formatting using std::format. More...

#include <logger.hpp>

Public Types

using Level = rclcpp::Logger::Level

Public Member Functions

 Logger (NodeInterfaces node)
 Construct from node like object with the required interfaces.
void set_level (Level level)
 Set output level of the stored logger.
template<typename... Args>
void debug (std::format_string< Args... > fmt, Args &&... args)
 Log at the debug specified in the name.
template<typename... Args>
void info (std::format_string< Args... > fmt, Args &&... args)
 Log at the info specified in the name.
template<typename... Args>
void warning (std::format_string< Args... > fmt, Args &&... args)
 Log at the warning specified in the name.
template<typename... Args>
void error (std::format_string< Args... > fmt, Args &&... args)
 Log at the error specified in the name.
template<typename... Args>
void fatal (std::format_string< Args... > fmt, Args &&... args)
 Log at the fatal specified in the name.
template<auto LocTag = MRS_LIB_LOGGER_UNIQUE_TAG, typename... Args>
void debug_once (std::format_string< Args... > fmt, Args &&... args)
 Log once at the debug specified in the name.
template<auto LocTag = MRS_LIB_LOGGER_UNIQUE_TAG, typename... Args>
void info_once (std::format_string< Args... > fmt, Args &&... args)
 Log once at the info specified in the name.
template<auto LocTag = MRS_LIB_LOGGER_UNIQUE_TAG, typename... Args>
void warning_once (std::format_string< Args... > fmt, Args &&... args)
 Log once at the warning specified in the name.
template<auto LocTag = MRS_LIB_LOGGER_UNIQUE_TAG, typename... Args>
void error_once (std::format_string< Args... > fmt, Args &&... args)
 Log once at the error specified in the name.
template<auto LocTag = MRS_LIB_LOGGER_UNIQUE_TAG, typename... Args>
void fatal_once (std::format_string< Args... > fmt, Args &&... args)
 Log once at the fatal specified in the name.
template<auto LocTag = MRS_LIB_LOGGER_UNIQUE_TAG, typename... Args>
void debug_throttle (std::chrono::milliseconds duration, std::format_string< Args... > fmt, Args &&... args)
 Log at the debug specified in the name with a maximum rate.
template<auto LocTag = MRS_LIB_LOGGER_UNIQUE_TAG, typename... Args>
void info_throttle (std::chrono::milliseconds duration, std::format_string< Args... > fmt, Args &&... args)
 Log at the info specified in the name with a maximum rate.
template<auto LocTag = MRS_LIB_LOGGER_UNIQUE_TAG, typename... Args>
void warning_throttle (std::chrono::milliseconds duration, std::format_string< Args... > fmt, Args &&... args)
 Log at the warning specified in the name with a maximum rate.
template<auto LocTag = MRS_LIB_LOGGER_UNIQUE_TAG, typename... Args>
void error_throttle (std::chrono::milliseconds duration, std::format_string< Args... > fmt, Args &&... args)
 Log at the error specified in the name with a maximum rate.
template<auto LocTag = MRS_LIB_LOGGER_UNIQUE_TAG, typename... Args>
void fatal_throttle (std::chrono::milliseconds duration, std::format_string< Args... > fmt, Args &&... args)
 Log at the fatal specified in the name with a maximum rate.

Detailed Description

Wrapper for rclcpp::Logger with formatting using std::format.

This wrapper can be used to wrap rclcpp::Logger and call log functions without using the rclcpp macros.

The log methods use std::format to format the messages. This allows adding formatting for custom types by specializing the std::formatter struct.

Member Function Documentation

◆ debug()

template<typename... Args>
void mrs_lib::Logger::debug ( std::format_string< Args... > fmt,
Args &&... args )
inline

Log at the debug specified in the name.

Parameters
fmtFormat string.
argsArguments to format.

◆ debug_once()

template<auto LocTag = MRS_LIB_LOGGER_UNIQUE_TAG, typename... Args>
void mrs_lib::Logger::debug_once ( std::format_string< Args... > fmt,
Args &&... args )
inline

Log once at the debug specified in the name.

Parameters
fmtFormat string.
argsArguments to format. Only the first pass at each call site will generate the output, the rest will be ignored.

◆ debug_throttle()

template<auto LocTag = MRS_LIB_LOGGER_UNIQUE_TAG, typename... Args>
void mrs_lib::Logger::debug_throttle ( std::chrono::milliseconds duration,
std::format_string< Args... > fmt,
Args &&... args )
inline

Log at the debug specified in the name with a maximum rate.

Parameters
durationMinimum time between two consecutive logs from this call site.
fmtFormat string.
argsArguments to format.

◆ error()

template<typename... Args>
void mrs_lib::Logger::error ( std::format_string< Args... > fmt,
Args &&... args )
inline

Log at the error specified in the name.

Parameters
fmtFormat string.
argsArguments to format.

◆ error_once()

template<auto LocTag = MRS_LIB_LOGGER_UNIQUE_TAG, typename... Args>
void mrs_lib::Logger::error_once ( std::format_string< Args... > fmt,
Args &&... args )
inline

Log once at the error specified in the name.

Parameters
fmtFormat string.
argsArguments to format. Only the first pass at each call site will generate the output, the rest will be ignored.

◆ error_throttle()

template<auto LocTag = MRS_LIB_LOGGER_UNIQUE_TAG, typename... Args>
void mrs_lib::Logger::error_throttle ( std::chrono::milliseconds duration,
std::format_string< Args... > fmt,
Args &&... args )
inline

Log at the error specified in the name with a maximum rate.

Parameters
durationMinimum time between two consecutive logs from this call site.
fmtFormat string.
argsArguments to format.

◆ fatal()

template<typename... Args>
void mrs_lib::Logger::fatal ( std::format_string< Args... > fmt,
Args &&... args )
inline

Log at the fatal specified in the name.

Parameters
fmtFormat string.
argsArguments to format.

◆ fatal_once()

template<auto LocTag = MRS_LIB_LOGGER_UNIQUE_TAG, typename... Args>
void mrs_lib::Logger::fatal_once ( std::format_string< Args... > fmt,
Args &&... args )
inline

Log once at the fatal specified in the name.

Parameters
fmtFormat string.
argsArguments to format. Only the first pass at each call site will generate the output, the rest will be ignored.

◆ fatal_throttle()

template<auto LocTag = MRS_LIB_LOGGER_UNIQUE_TAG, typename... Args>
void mrs_lib::Logger::fatal_throttle ( std::chrono::milliseconds duration,
std::format_string< Args... > fmt,
Args &&... args )
inline

Log at the fatal specified in the name with a maximum rate.

Parameters
durationMinimum time between two consecutive logs from this call site.
fmtFormat string.
argsArguments to format.

◆ info()

template<typename... Args>
void mrs_lib::Logger::info ( std::format_string< Args... > fmt,
Args &&... args )
inline

Log at the info specified in the name.

Parameters
fmtFormat string.
argsArguments to format.

◆ info_once()

template<auto LocTag = MRS_LIB_LOGGER_UNIQUE_TAG, typename... Args>
void mrs_lib::Logger::info_once ( std::format_string< Args... > fmt,
Args &&... args )
inline

Log once at the info specified in the name.

Parameters
fmtFormat string.
argsArguments to format. Only the first pass at each call site will generate the output, the rest will be ignored.

◆ info_throttle()

template<auto LocTag = MRS_LIB_LOGGER_UNIQUE_TAG, typename... Args>
void mrs_lib::Logger::info_throttle ( std::chrono::milliseconds duration,
std::format_string< Args... > fmt,
Args &&... args )
inline

Log at the info specified in the name with a maximum rate.

Parameters
durationMinimum time between two consecutive logs from this call site.
fmtFormat string.
argsArguments to format.

◆ set_level()

void mrs_lib::Logger::set_level ( Level level)
inline

Set output level of the stored logger.

This affects the wrapped rclcpp::Logger, so it will for all calls using that logger, not only using this wrapper.

◆ warning()

template<typename... Args>
void mrs_lib::Logger::warning ( std::format_string< Args... > fmt,
Args &&... args )
inline

Log at the warning specified in the name.

Parameters
fmtFormat string.
argsArguments to format.

◆ warning_once()

template<auto LocTag = MRS_LIB_LOGGER_UNIQUE_TAG, typename... Args>
void mrs_lib::Logger::warning_once ( std::format_string< Args... > fmt,
Args &&... args )
inline

Log once at the warning specified in the name.

Parameters
fmtFormat string.
argsArguments to format. Only the first pass at each call site will generate the output, the rest will be ignored.

◆ warning_throttle()

template<auto LocTag = MRS_LIB_LOGGER_UNIQUE_TAG, typename... Args>
void mrs_lib::Logger::warning_throttle ( std::chrono::milliseconds duration,
std::format_string< Args... > fmt,
Args &&... args )
inline

Log at the warning specified in the name with a maximum rate.

Parameters
durationMinimum time between two consecutive logs from this call site.
fmtFormat string.
argsArguments to format.

The documentation for this class was generated from the following file:
  • /home/runner/work/mrs_lib/mrs_lib/include/mrs_lib/logger.hpp