Public Types | Public Member Functions | Public Attributes | Protected Member Functions | Friends | List of all members
cras::LogHelper Class Referenceabstract

This class (reps. its descendants) provides unified access to ROS logging functions, be it ROS_* or NODELET_*. More...

#include <log_utils.h>

Inheritance diagram for cras::LogHelper:
Inheritance graph
[legend]

Public Types

typedef ::std::shared_ptr< const ::cras::LogHelperConstPtr
 Const pointer to LogHelper. More...
 
typedef ::std::shared_ptr<::cras::LogHelperPtr
 Pointer to LogHelper. More...
 

Public Member Functions

virtual void checkLogLocationEnabled (::ros::console::LogLocation *loc) const
 Check whether the log location is enabled. More...
 
virtual const void * getId () const
 Return a unique identifier of this logger. These IDs are used for determining which logger has already logged something. More...
 
virtual ::ros::Time getTimeNow () const
 Get current time (used for throttling messages). By default, ROS time is returned, with fallback to wall time if ROS time is not initialized. More...
 
void initialize () const
 Initialize the logger. This function does what it needs and then calls initializeImpl(). More...
 
void initializeLogLocation (::ros::console::LogLocation *loc, const std::string &name, ::ros::console::Level level) const
 Initialize the given log location with proper data for later use. This is the function called from macros. This function checks whether log level is within bounds, corrects it if needed, calls initializeLogLocaionImpl(), and, if the passed log level was wrong, logs an additional error (after the log location has been initialized by the impl function). More...
 
void log (::ros::console::Level level, ::std::string format,...) const
 Log a message using the given log severity. More...
 
void log (::ros::console::Level level, const char *format,...) const
 Log a message using the given log severity. More...
 
 LogHelper ()
 
 LogHelper (const LogHelper &)=delete
 
 LogHelper (LogHelper &&)=delete
 
virtual void logString (void *logger, ::ros::console::Level level, const ::std::string &str, const char *file, uint32_t line, const char *function) const =0
 Write the given string to the log. More...
 
LogHelperoperator= (const LogHelper &)=delete
 
LogHelperoperator= (LogHelper &&)=delete
 
void print (::ros::console::FilterBase *filter, void *logger, ::ros::console::Level level, const ::std::string &str, const char *file, int line, const char *function) const
 Print function used by the macros. It basically just relays its work to logString(). More...
 
void print (::ros::console::FilterBase *filter, void *logger, ::ros::console::Level level, const ::std::stringstream &ss, const char *file, int line, const char *function) const
 Print function used by the macros. It basically just relays its work to logString(). More...
 
void void print (::ros::console::FilterBase *filter, void *logger, ::ros::console::Level level, const char *file, int line, const char *function, ::std::string fmt,...) const
 Print function used by the macros. It basically just relays its work to logString(). More...
 
void print (::ros::console::FilterBase *filter, void *logger, ::ros::console::Level level, const char *file, int line, const char *function, const char *fmt,...) const ROSCONSOLE_PRINTF_ATTRIBUTE(8
 Print function used by the macros. It basically just relays its work to logString(). More...
 
void print (::ros::console::Level level, const ::std::string &text) const
 Log a message using the given log severity. More...
 
void setGlobalLogger () const
 
virtual void setLogLocationLevel (::ros::console::LogLocation *loc, ::ros::console::Level level) const
 Set level of a log location. This is only called when global logging level changes. More...
 
virtual ~LogHelper ()=default
 

Public Attributes

bool initialized {false}
 Whether initialize() has been called at least once. Subclasses are required to handle this invariant. More...
 

Protected Member Functions

virtual void initializeImpl () const =0
 Initialize the logger. It is not needed to check initialized as this function is only called when it was false. More...
 
virtual void initializeLogLocationImpl (::ros::console::LogLocation *loc, const std::string &name, ::ros::console::Level level) const =0
 Initialize the given log location with proper data for later use. This function is only called if the log location was not already initialized. More...
 

Friends

class WrapperLogHelper
 

Detailed Description

This class (reps. its descendants) provides unified access to ROS logging functions, be it ROS_* or NODELET_*.

Subclasses only need to implement the print* functions that print a pre-formatted string.

Definition at line 52 of file log_utils.h.

Member Typedef Documentation

◆ ConstPtr

typedef ::std::shared_ptr<const ::cras::LogHelper> cras::LogHelper::ConstPtr

Const pointer to LogHelper.

Definition at line 56 of file log_utils.h.

◆ Ptr

typedef ::std::shared_ptr<::cras::LogHelper> cras::LogHelper::Ptr

Pointer to LogHelper.

Definition at line 55 of file log_utils.h.

Constructor & Destructor Documentation

◆ LogHelper() [1/3]

cras::LogHelper::LogHelper ( )

◆ ~LogHelper()

virtual cras::LogHelper::~LogHelper ( )
virtualdefault

◆ LogHelper() [2/3]

cras::LogHelper::LogHelper ( const LogHelper )
delete

◆ LogHelper() [3/3]

cras::LogHelper::LogHelper ( LogHelper &&  )
delete

Member Function Documentation

◆ checkLogLocationEnabled()

virtual void cras::LogHelper::checkLogLocationEnabled ( ::ros::console::LogLocation loc) const
virtual

Check whether the log location is enabled.

Parameters
[in]locThe location to check.

Reimplemented in cras::WrapperLogHelper, cras::RosconsoleLogHelper, and cras::MemoryLogHelper.

◆ getId()

virtual const void* cras::LogHelper::getId ( ) const
virtual

Return a unique identifier of this logger. These IDs are used for determining which logger has already logged something.

Returns
An ID.

Reimplemented in cras::WrapperLogHelper.

◆ getTimeNow()

virtual ::ros::Time cras::LogHelper::getTimeNow ( ) const

Get current time (used for throttling messages). By default, ROS time is returned, with fallback to wall time if ROS time is not initialized.

Returns
Current time.

◆ initialize()

void cras::LogHelper::initialize ( ) const

Initialize the logger. This function does what it needs and then calls initializeImpl().

◆ initializeImpl()

virtual void cras::LogHelper::initializeImpl ( ) const
protectedpure virtual

Initialize the logger. It is not needed to check initialized as this function is only called when it was false.

Implemented in cras::WrapperLogHelper, cras::RosconsoleLogHelper, and cras::MemoryLogHelper.

◆ initializeLogLocation()

void cras::LogHelper::initializeLogLocation ( ::ros::console::LogLocation loc,
const std::string &  name,
::ros::console::Level  level 
) const

Initialize the given log location with proper data for later use. This is the function called from macros. This function checks whether log level is within bounds, corrects it if needed, calls initializeLogLocaionImpl(), and, if the passed log level was wrong, logs an additional error (after the log location has been initialized by the impl function).

Parameters
[out]locThe location to fill.
[in]nameName of the logger.
[in]levelLogging level of the message at this location.

◆ initializeLogLocationImpl()

virtual void cras::LogHelper::initializeLogLocationImpl ( ::ros::console::LogLocation loc,
const std::string &  name,
::ros::console::Level  level 
) const
protectedpure virtual

Initialize the given log location with proper data for later use. This function is only called if the log location was not already initialized.

Parameters
[out]locThe location to fill.
[in]nameName of the logger.
[in]levelLogging level of the message at this location. The level is already checked to be valid.

◆ log() [1/2]

void cras::LogHelper::log ( ::ros::console::Level  level,
::std::string  format,
  ... 
) const

Log a message using the given log severity.

Parameters
[in]levelLog severity level (one of the ros::console::Level enum constants).
[in]formatprintf-like format string.
[in]...Arguments to print.

◆ log() [2/2]

void cras::LogHelper::log ( ::ros::console::Level  level,
const char *  format,
  ... 
) const

Log a message using the given log severity.

Parameters
[in]levelLog severity level (one of the ros::console::Level enum constants).
[in]formatprintf-like format string.
[in]...Arguments to print.

◆ logString()

virtual void cras::LogHelper::logString ( void *  logger,
::ros::console::Level  level,
const ::std::string &  str,
const char *  file,
uint32_t  line,
const char *  function 
) const
pure virtual

Write the given string to the log.

Parameters
[in]loggerPrivate logger data read from the relevant log location (set by initializeLogLocation()).
[in]levelLevel of the logged message.
[in]strLogged message.
[in]fileFile at which the logging macro has been called.
[in]lineLine on which the logging macro has been called.
[in]functionName of function from which the logging macro has been called.

Implemented in cras::WrapperLogHelper, and cras::RosconsoleLogHelper.

◆ operator=() [1/2]

LogHelper& cras::LogHelper::operator= ( const LogHelper )
delete

◆ operator=() [2/2]

LogHelper& cras::LogHelper::operator= ( LogHelper &&  )
delete

◆ print() [1/5]

void cras::LogHelper::print ( ::ros::console::FilterBase filter,
void *  logger,
::ros::console::Level  level,
const ::std::string &  str,
const char *  file,
int  line,
const char *  function 
) const

Print function used by the macros. It basically just relays its work to logString().

◆ print() [2/5]

void cras::LogHelper::print ( ::ros::console::FilterBase filter,
void *  logger,
::ros::console::Level  level,
const ::std::stringstream &  ss,
const char *  file,
int  line,
const char *  function 
) const

Print function used by the macros. It basically just relays its work to logString().

◆ print() [3/5]

void void cras::LogHelper::print ( ::ros::console::FilterBase filter,
void *  logger,
::ros::console::Level  level,
const char *  file,
int  line,
const char *  function,
::std::string  fmt,
  ... 
) const

Print function used by the macros. It basically just relays its work to logString().

◆ print() [4/5]

void cras::LogHelper::print ( ::ros::console::FilterBase filter,
void *  logger,
::ros::console::Level  level,
const char *  file,
int  line,
const char *  function,
const char *  fmt,
  ... 
) const

Print function used by the macros. It basically just relays its work to logString().

◆ print() [5/5]

void cras::LogHelper::print ( ::ros::console::Level  level,
const ::std::string &  text 
) const

Log a message using the given log severity.

Parameters
[in]levelLog severity level (one of the ros::console::Level enum constants).
[in]textThe message to log.

◆ setGlobalLogger()

void cras::LogHelper::setGlobalLogger ( ) const

◆ setLogLocationLevel()

virtual void cras::LogHelper::setLogLocationLevel ( ::ros::console::LogLocation loc,
::ros::console::Level  level 
) const
virtual

Set level of a log location. This is only called when global logging level changes.

Parameters
[in,out]locThe location to update.
[in]levelThe new level.

Reimplemented in cras::WrapperLogHelper, cras::RosconsoleLogHelper, and cras::MemoryLogHelper.

Friends And Related Function Documentation

◆ WrapperLogHelper

friend class WrapperLogHelper
friend

Definition at line 199 of file log_utils.h.

Member Data Documentation

◆ initialized

bool cras::LogHelper::initialized {false}
mutable

Whether initialize() has been called at least once. Subclasses are required to handle this invariant.

Definition at line 68 of file log_utils.h.


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


cras_cpp_common
Author(s): Martin Pecka
autogenerated on Sat Dec 14 2024 03:51:05