class mrpt::system::COutputLogger
Versatile class for consistent logging and management of output messages.
COutputLogger is a versatile class for logging messages either to the terminal window or to an external file. Class instances can take messages in std::string using the logStr class methods. The following macros are also provided for usage within a class that inherits from COutputLogger :
// Plain strings: MRPT_LOG_DEBUG("This will be shown only if verbosity level is LVL_DEBUG."); MRPT_LOG_ERROR("This message will be always shown."); // printf-like versions: MRPT_LOG_ERROR_FMT("Out of range value: %i.", int_param); // stream-like versions: MRPT_LOG_ERROR_STREAM("Out of range value: " << int_param << " more vars: " << other_var); // Minimum period (in seconds) between messages: MRPT_LOG_THROTTLE_DEBUG_STREAM(5.0, "Var=" << value << " foo=" << foo_var); // Only once: MRPT_LOG_ONCE_WARN("Notice: blah blah");
From outside of a class inheriting from COutputLogger the following MRPT_UNSCOPED_{START|END}
macros are provided:
MRPT_UNSCOPED_LOGGER_START; MRPT_LOG_WARN("blah"); MRPT_LOG_ERROR_STREAM("error: " << strval); MRPT_UNSCOPED_LOGGER_END;
Logger instance keeps the messages in an internal container so that upon request it can dump them either to the console or to an external file altogether.
The message, when printed in the terminal window, is colored according to the logger’s current verbosity/logging level (Logging level with which the underlying TMsg instance was instantiatedd). The available verbosity levels as well as their corresponding colors are listed below:
LVL_DEBUG => CONCOL_BLUE
LVL_INFO => CONCOL_NORMAL
LVL_WARN => CONCOL_GREEN
LVL_ERROR => CONCOL_RED
Logged messages are displayed in the screen if the current logger level is higher than m_min_verbosity_level (logger ignores those messages altogether). This can be used for filtering the output messages according to their importance (e.g. show only error messages by issuing setMinLoggingLevel(LVL_ERROR)). Default logging level is LVL_INFO.
User may receive callbacks whenever a message is displayed to console by using logRegisterCallback(). If for some reason the callbacks are not needed any more, use logDeregisterCallback() to stop receiving calls. This mechanism is useful in case of showing the messages to a GUI, transmiting them to a remote machine, etc.
Note that only those messages whose “importance level” will be printed and sent to user callbacks. However, all messages will be stored and saved to a file with writeLogToFile() despite the current filter, if logging_enable_keep_record
is set to true
(Default= false
).
By default every logged message is going to be dumped to the standard output as well (if VerbosityLevel > m_min_verbosity_level). Unset logging_enable_console_output class variable if that’s not the desired behavior
See also:
setLoggingLevel, setMinLoggingLevel
#include <mrpt/system/COutputLogger.h> class COutputLogger { public: // structs struct TMsg; // construction COutputLogger(std::string_view name); COutputLogger(); }; // direct descendants template < size_t VEH_SIZE, size_t OBS_SIZE, size_t FEAT_SIZE, size_t ACT_SIZE, typename KFTYPE = double > class CKalmanFilterCapable; template <class GRAPH_T = typename mrpt::graphs::CNetworkOfPoses2DInf> class CGraphSlamEngine; template <class GRAPH_T = typename mrpt::graphs::CNetworkOfPoses2DInf> class CRegistrationDeciderOrOptimizer; template < class PARTICLE_TYPE, class MYSELF, mrpt::bayes::particle_storage_mode STORAGE > class PF_implementation; class CGridMapAlignerApp; class DataSourceRawlog; class ICP_SLAM_App_Base; class KFSLAMApp; class MonteCarloLocalization_Base; class RBPF_SLAM_App_Base; class RawlogGrabberApp; class CParticleFilter; class CServerTCPSocket; class CDetectorDoorCrossing; class ScalarFactorGraph; class CWindowManager; class C2DRangeFinderAbstract; class CCANBusReader; class CCameraSensor; class CGPSInterface; class CNationalInstrumentsDAQ; class CPhidgetInterfaceKitProximitySensors; class CRoboticHeadInterface; class CTuMicos; class CRandomFieldGridMap2D; class CRandomFieldGridMap3D; template <typename VECTORTYPE = CVectorDouble, class USERPARAM = VECTORTYPE> class CLevenbergMarquardtTempl; template < typename NUMTYPE = double, typename DATASET = CMatrixDynamic<NUMTYPE>, typename MODEL = CMatrixDynamic<NUMTYPE> > class RANSAC_Template; class CAbstractNavigator; class CRobot2NavInterface; class CIncrementalMapPartitioner; class CMetricMapBuilder; class CMetricMapsAlignmentAlgorithm; class CControlledRateTimer; class CTimeLogger;
Construction
COutputLogger(std::string_view name)
Construct a COutputLogger instance with the given name as the instance name.
Call to this constructor can be used instead of first initializing the object and then explicitly setting the name like in the following case:
COutputLogger a_logger; a_logger.setLoggerName("logger_name");
COutputLogger()
Default constructor.