libmove3d-planners
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Macros Groups Pages
Macros | Typedefs | Functions
Logger.h File Reference

This file implements macros to help with the logging, in a way similar to ROS, using log4cxx. More...

#include <log4cxx/logger.h>
#include <iostream>

Go to the source code of this file.

Macros

#define INIT_MOVE3D_LOG(name)   log4cxx::LoggerPtr __move3d_logger__ = logm3d::getLogger(name)
 INIT_MOVE3D_LOG macro creates a logger to be used by AutoLogger macros in the scope where it is called. More...
 
#define MOVE3D_STATIC_LOGGER   static log4cxx::LoggerPtr __move3d_logger__
 MOVE3D_STATIC_LOGGER macro defines a static logger for the class. More...
 
#define INIT_MOVE3D_STATIC_LOGGER(classname, loggername)   log4cxx::LoggerPtr classname::__move3d_logger__ = logm3d::getLogger(loggername)
 INIT_MOVE3D_STATIC_LOGGER() macro is to be called in the class implementation file (.cpp) to instantiate the static logger. More...
 
#define LOGM3D_TRACE(_logger_, msg)   LOG4CXX_TRACE(_logger_,msg)
 The following macros does not need INIT_MOVE3D_LOG to be called, and can be used to have different loggers in a same cpp file. More...
 
#define LOGM3D_DEBUG(_logger_, msg)   LOG4CXX_DEBUG(_logger_,msg)
 
#define LOGM3D_INFO(_logger_, msg)   LOG4CXX_INFO(_logger_,msg)
 
#define LOGM3D_WARN(_logger_, msg)   LOG4CXX_WARN(_logger_,msg)
 
#define LOGM3D_ERROR(_logger_, msg)   LOG4CXX_ERROR(_logger_,msg)
 
#define LOGM3D_FATAL(_logger_, msg)   LOG4CXX_FATAL(_logger_,msg)
 
#define M3D_TRACE(msg)   LOGM3D_TRACE(__move3d_logger__,msg)
 
#define M3D_DEBUG(msg)   LOGM3D_DEBUG(__move3d_logger__,msg)
 Logs a message with the logger defined in the scope with macro of AutoLogger. More...
 
#define M3D_INFO(msg)   LOGM3D_INFO(__move3d_logger__,msg)
 
#define M3D_WARN(msg)   LOGM3D_WARN(__move3d_logger__,msg)
 
#define M3D_ERROR(msg)   LOGM3D_ERROR(__move3d_logger__,msg)
 
#define M3D_FATAL(msg)   LOGM3D_FATAL(__move3d_logger__,msg)
 

Typedefs

typedef log4cxx::LoggerPtr logm3d::LoggerPtr
 

Functions

void logm3d::initializePlannerLogger ()
 to be called to initialize the logging system to its defaults (once in a session)
 
LoggerPtr logm3d::getLogger (std::string name)
 
LoggerPtr logm3d::getLoggerDataFile (std::string name, std::string file_path)
 
LoggerPtr logm3d::getLoggerConsoleAndFile (std::string name, std::string file_path)
 

Detailed Description

This file implements macros to help with the logging, in a way similar to ROS, using log4cxx.

Author
Jules Waldhart
Date
22 april 2015

The macros defined here have to be called to initialize and then use logging in a class/method/file/function... The macros allow to log for different levels, which are (ordered): TRACE < DEBUG < INFO < WARN < ERROR < FATAL see http://wiki.ros.org/Verbosity%20Levels for information about the purpose of each level

It is possible to select at execution time the lower log level that will be displayed for each logger (in each cpp file) see http://logging.apache.org/log4cxx/usage.html for a short introduction to log4cxx

You can directly use log4cxx API, but here you will find some helpers to make it easier and faster to implement. Also, if for some reason the logging system needs to be changed, using the logm3d interface defined here will help in the changing process.

Names And Hierarchy

The logger names have to be choosen wisely. There is a hierarchy of names, so for instance, planners is an ancestor of planners.hrics.mho and the parent of planners.hrics. By default, a logger inherits its parents property, but it can be overriden. So for debugging all HRICS module, one can disable debug infromation for the root (by default, no debug information anywhere) and set planners.hrics logging level to debug, only the debug (and higher) level information will be print.

When naming a logger, you need to keep this in mind, so that an other developer/user can choose to display only what he needs. So do not hesitate to go deep in the hierarchy (e.g. planners.hrics.mho.grid.cell)

Configuration files

The system will look for different file, until finding one, testing in that order:

Macro Definition Documentation

#define LOGM3D_TRACE (   _logger_,
  msg 
)    LOG4CXX_TRACE(_logger_,msg)

The following macros does not need INIT_MOVE3D_LOG to be called, and can be used to have different loggers in a same cpp file.

Parameters
_logger_a logm3d::LoggerPtr to use as logger
msga std::string, char*, wchar*, the insertion operator (<<) can be used (see log4cxx doc)

These loggers are obtained through the various logm3d::getLogger() and similar functions, (or log4cxx::Logger::getLogger() : to be avoided, create a logm3d logger instead)