This class (reps. its descendants) provides unified access to ROS logging functions, be it ROS_* or NODELET_*. More...
#include <log_utils.h>
Public Types | |
typedef ::std::shared_ptr< const ::cras::LogHelper > | ConstPtr |
Const pointer to LogHelper . More... | |
typedef ::std::shared_ptr<::cras::LogHelper > | Ptr |
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... | |
LogHelper & | operator= (const LogHelper &)=delete |
LogHelper & | operator= (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 |
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.
typedef ::std::shared_ptr<const ::cras::LogHelper> cras::LogHelper::ConstPtr |
Const pointer to LogHelper
.
Definition at line 56 of file log_utils.h.
typedef ::std::shared_ptr<::cras::LogHelper> cras::LogHelper::Ptr |
Pointer to LogHelper
.
Definition at line 55 of file log_utils.h.
cras::LogHelper::LogHelper | ( | ) |
|
virtualdefault |
|
delete |
|
delete |
|
virtual |
Check whether the log location is enabled.
[in] | loc | The location to check. |
Reimplemented in cras::WrapperLogHelper, cras::RosconsoleLogHelper, and cras::MemoryLogHelper.
|
virtual |
Return a unique identifier of this logger. These IDs are used for determining which logger has already logged something.
Reimplemented in cras::WrapperLogHelper.
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.
void cras::LogHelper::initialize | ( | ) | const |
Initialize the logger. This function does what it needs and then calls initializeImpl()
.
|
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.
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).
[out] | loc | The location to fill. |
[in] | name | Name of the logger. |
[in] | level | Logging level of the message at this location. |
|
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.
[out] | loc | The location to fill. |
[in] | name | Name of the logger. |
[in] | level | Logging level of the message at this location. The level is already checked to be valid. |
void cras::LogHelper::log | ( | ::ros::console::Level | level, |
::std::string | format, | ||
... | |||
) | const |
Log a message using the given log severity.
[in] | level | Log severity level (one of the ros::console::Level enum constants). |
[in] | format | printf-like format string. |
[in] | ... | Arguments to print. |
void cras::LogHelper::log | ( | ::ros::console::Level | level, |
const char * | format, | ||
... | |||
) | const |
Log a message using the given log severity.
[in] | level | Log severity level (one of the ros::console::Level enum constants). |
[in] | format | printf-like format string. |
[in] | ... | Arguments to print. |
|
pure virtual |
Write the given string to the log.
[in] | logger | Private logger data read from the relevant log location (set by initializeLogLocation() ). |
[in] | level | Level of the logged message. |
[in] | str | Logged message. |
[in] | file | File at which the logging macro has been called. |
[in] | line | Line on which the logging macro has been called. |
[in] | function | Name of function from which the logging macro has been called. |
Implemented in cras::WrapperLogHelper, and cras::RosconsoleLogHelper.
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()
.
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()
.
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()
.
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()
.
void cras::LogHelper::print | ( | ::ros::console::Level | level, |
const ::std::string & | text | ||
) | const |
Log a message using the given log severity.
[in] | level | Log severity level (one of the ros::console::Level enum constants). |
[in] | text | The message to log. |
void cras::LogHelper::setGlobalLogger | ( | ) | const |
|
virtual |
Set level of a log location. This is only called when global logging level changes.
[in,out] | loc | The location to update. |
[in] | level | The new level. |
Reimplemented in cras::WrapperLogHelper, cras::RosconsoleLogHelper, and cras::MemoryLogHelper.
|
friend |
Definition at line 199 of file log_utils.h.
|
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.