cisst-saw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Macros
cmnLogger.h File Reference

Declaration of cmnLogger amd macros for human readable logging. More...

#include <cisstCommon/cmnPortability.h>
#include <cisstCommon/cmnLogLoD.h>
#include <cisstCommon/cmnLODOutputMultiplexer.h>
#include <cisstCommon/cmnMultiplexerStreambuf.h>
#include <cisstCommon/cmnLODMultiplexerStreambuf.h>
#include <string>
#include <vector>
#include <fstream>
#include <cisstCommon/cmnExport.h>

Go to the source code of this file.

Classes

class  cmnLogger
 Class to glue the class register, the output multiplexer and the message level of detail to form the logging entity of cisst. More...
 

Macros

#define _cmnLogger_h
 
#define BYPASS_CMN_LOG
 
#define CMN_LOG_CLASS_INSTANCE(objectPointer, lod)   std::cout
 
#define CMN_LOG_CLASS(lod)   CMN_LOG_CLASS_INSTANCE(this, lod)
 
#define CMN_LOG(lod)   std::cout
 
#define CMN_LOG_DETAILS   "File: " << cmnLogger::ExtractFileName(__FILE__) << " Line: " << __LINE__ << " - "
 
#define CMN_LOG_CLASS_INSTANCE_INIT_ERROR(objectPointer)   CMN_LOG_CLASS_INSTANCE(objectPointer, CMN_LOG_LEVEL_INIT_ERROR) << CMN_LOG_DETAILS << " "
 
#define CMN_LOG_CLASS_INSTANCE_INIT_WARNING(objectPointer)   CMN_LOG_CLASS_INSTANCE(objectPointer, CMN_LOG_LEVEL_INIT_WARNING)
 
#define CMN_LOG_CLASS_INSTANCE_INIT_VERBOSE(objectPointer)   CMN_LOG_CLASS_INSTANCE(objectPointer, CMN_LOG_LEVEL_INIT_VERBOSE)
 
#define CMN_LOG_CLASS_INSTANCE_INIT_DEBUG(objectPointer)   CMN_LOG_CLASS_INSTANCE(objectPointer, CMN_LOG_LEVEL_INIT_DEBUG)
 
#define CMN_LOG_CLASS_INSTANCE_RUN_ERROR(objectPointer)   CMN_LOG_CLASS_INSTANCE(objectPointer, CMN_LOG_LEVEL_RUN_ERROR) << CMN_LOG_DETAILS << " "
 
#define CMN_LOG_CLASS_INSTANCE_RUN_WARNING(objectPointer)   CMN_LOG_CLASS_INSTANCE(objectPointer, CMN_LOG_LEVEL_RUN_WARNING)
 
#define CMN_LOG_CLASS_INSTANCE_RUN_VERBOSE(objectPointer)   CMN_LOG_CLASS_INSTANCE(objectPointer, CMN_LOG_LEVEL_RUN_VERBOSE)
 
#define CMN_LOG_CLASS_INSTANCE_RUN_DEBUG(objectPointer)   CMN_LOG_CLASS_INSTANCE(objectPointer, CMN_LOG_LEVEL_RUN_DEBUG)
 
#define CMN_LOG_CLASS_INIT_ERROR   CMN_LOG_CLASS(CMN_LOG_LEVEL_INIT_ERROR) << CMN_LOG_DETAILS << " "
 
#define CMN_LOG_CLASS_INIT_WARNING   CMN_LOG_CLASS(CMN_LOG_LEVEL_INIT_WARNING)
 
#define CMN_LOG_CLASS_INIT_VERBOSE   CMN_LOG_CLASS(CMN_LOG_LEVEL_INIT_VERBOSE)
 
#define CMN_LOG_CLASS_INIT_DEBUG   CMN_LOG_CLASS(CMN_LOG_LEVEL_INIT_DEBUG)
 
#define CMN_LOG_CLASS_RUN_ERROR   CMN_LOG_CLASS(CMN_LOG_LEVEL_RUN_ERROR) << CMN_LOG_DETAILS << " "
 
#define CMN_LOG_CLASS_RUN_WARNING   CMN_LOG_CLASS(CMN_LOG_LEVEL_RUN_WARNING)
 
#define CMN_LOG_CLASS_RUN_VERBOSE   CMN_LOG_CLASS(CMN_LOG_LEVEL_RUN_VERBOSE)
 
#define CMN_LOG_CLASS_RUN_DEBUG   CMN_LOG_CLASS(CMN_LOG_LEVEL_RUN_DEBUG)
 
#define CMN_LOG_INIT_ERROR   CMN_LOG(CMN_LOG_LEVEL_INIT_ERROR) << CMN_LOG_DETAILS << " "
 
#define CMN_LOG_INIT_WARNING   CMN_LOG(CMN_LOG_LEVEL_INIT_WARNING)
 
#define CMN_LOG_INIT_VERBOSE   CMN_LOG(CMN_LOG_LEVEL_INIT_VERBOSE)
 
#define CMN_LOG_INIT_DEBUG   CMN_LOG(CMN_LOG_LEVEL_INIT_DEBUG)
 
#define CMN_LOG_RUN_ERROR   CMN_LOG(CMN_LOG_LEVEL_RUN_ERROR) << CMN_LOG_DETAILS << " "
 
#define CMN_LOG_RUN_WARNING   CMN_LOG(CMN_LOG_LEVEL_RUN_WARNING)
 
#define CMN_LOG_RUN_VERBOSE   CMN_LOG(CMN_LOG_LEVEL_RUN_VERBOSE)
 
#define CMN_LOG_RUN_DEBUG   CMN_LOG(CMN_LOG_LEVEL_RUN_DEBUG)
 

Detailed Description

Declaration of cmnLogger amd macros for human readable logging.

Macro Definition Documentation

#define _cmnLogger_h
#define BYPASS_CMN_LOG
#define CMN_LOG (   lod)    std::cout

This macro is used to log human readable information within the scope of a global function (e.g. main()). It can also be used in classes which are not registered in cmnClassRegister (see also macros CMN_DECLARE_SERVICES and CMN_IMPLEMENT_SERVICES declared in cmnClassRegister.h). For a registered class, please use CMN_LOG_CLASS.

The message is streamed along with a Level of Detail to cmnLogger provided that the function and overall log masks allow the level of detail associated to the message. The overall mask can be set using cmnLogger::SetMask. The function mask can be set using cmnLogger::SetMaskFunction.

The macro creates an output stream if the level of detail of the message satisfies the criterion defined above. It can be used as any other output stream:

CMN_LOG_INIT_ERROR << "This is a message of LoD CMN_LOG_LEVEL_INIT_ERROR" << argc << std::endl;
Parameters
lodThe log level of detail of the message.
#define CMN_LOG_CLASS (   lod)    CMN_LOG_CLASS_INSTANCE(this, lod)
#define CMN_LOG_CLASS_INIT_DEBUG   CMN_LOG_CLASS(CMN_LOG_LEVEL_INIT_DEBUG)
#define CMN_LOG_CLASS_INIT_ERROR   CMN_LOG_CLASS(CMN_LOG_LEVEL_INIT_ERROR) << CMN_LOG_DETAILS << " "

Macros defined to use CMN_LOG_CLASS for a given level of detail.

#define CMN_LOG_CLASS_INIT_VERBOSE   CMN_LOG_CLASS(CMN_LOG_LEVEL_INIT_VERBOSE)
#define CMN_LOG_CLASS_INIT_WARNING   CMN_LOG_CLASS(CMN_LOG_LEVEL_INIT_WARNING)
#define CMN_LOG_CLASS_INSTANCE (   objectPointer,
  lod 
)    std::cout

This macro is used to log human readable information within a registered class. It can only be used within the scope of a method part of a class registered in the cmnClassRegister using the macros CMN_DECLARE_SERVICES and CMN_IMPLEMENT_SERVICES declared in cmnClassRegister.h. For a non registered class of a global function, please use CMN_LOG.

The message is streamed along with a Level of Detail to cmnLogger provided that two conditions are met:

The macro creates an output stream if the level of detail of the message satisfies the two criteria defined above. It can be used as any other output stream:

CMN_LOG_CLASS_INIT_DEBUG << "This is a message of LoD 4" << this->x << std::endl;
Parameters
lodThe log level of detail of the message.
Todo:
replace (CISST_OS == CISST_DARWIN) with a better solution for OS X logging compiler errors
#define CMN_LOG_CLASS_INSTANCE_INIT_DEBUG (   objectPointer)    CMN_LOG_CLASS_INSTANCE(objectPointer, CMN_LOG_LEVEL_INIT_DEBUG)
#define CMN_LOG_CLASS_INSTANCE_INIT_ERROR (   objectPointer)    CMN_LOG_CLASS_INSTANCE(objectPointer, CMN_LOG_LEVEL_INIT_ERROR) << CMN_LOG_DETAILS << " "

Macros defined to use CMN_LOG_CLASS_INSTANCE for a given level of detail.

#define CMN_LOG_CLASS_INSTANCE_INIT_VERBOSE (   objectPointer)    CMN_LOG_CLASS_INSTANCE(objectPointer, CMN_LOG_LEVEL_INIT_VERBOSE)
#define CMN_LOG_CLASS_INSTANCE_INIT_WARNING (   objectPointer)    CMN_LOG_CLASS_INSTANCE(objectPointer, CMN_LOG_LEVEL_INIT_WARNING)
#define CMN_LOG_CLASS_INSTANCE_RUN_DEBUG (   objectPointer)    CMN_LOG_CLASS_INSTANCE(objectPointer, CMN_LOG_LEVEL_RUN_DEBUG)
#define CMN_LOG_CLASS_INSTANCE_RUN_ERROR (   objectPointer)    CMN_LOG_CLASS_INSTANCE(objectPointer, CMN_LOG_LEVEL_RUN_ERROR) << CMN_LOG_DETAILS << " "
#define CMN_LOG_CLASS_INSTANCE_RUN_VERBOSE (   objectPointer)    CMN_LOG_CLASS_INSTANCE(objectPointer, CMN_LOG_LEVEL_RUN_VERBOSE)
#define CMN_LOG_CLASS_INSTANCE_RUN_WARNING (   objectPointer)    CMN_LOG_CLASS_INSTANCE(objectPointer, CMN_LOG_LEVEL_RUN_WARNING)
#define CMN_LOG_CLASS_RUN_DEBUG   CMN_LOG_CLASS(CMN_LOG_LEVEL_RUN_DEBUG)
#define CMN_LOG_CLASS_RUN_ERROR   CMN_LOG_CLASS(CMN_LOG_LEVEL_RUN_ERROR) << CMN_LOG_DETAILS << " "
#define CMN_LOG_CLASS_RUN_VERBOSE   CMN_LOG_CLASS(CMN_LOG_LEVEL_RUN_VERBOSE)
#define CMN_LOG_CLASS_RUN_WARNING   CMN_LOG_CLASS(CMN_LOG_LEVEL_RUN_WARNING)
#define CMN_LOG_DETAILS   "File: " << cmnLogger::ExtractFileName(__FILE__) << " Line: " << __LINE__ << " - "

This macro is used to add useful information to Log macros (CMN_LOG_CLASS and CMN_LOG). It provides the additional functionality of logging the file name and line number at which the message was generated.

For example:

CMN_LOG_INIT_ERROR << CMN_LOG_DETAILS << "Error occurs" << std::endl;

For any error with a very common message, this helps the programmer to quickly find the origin of the message in the source code.

#define CMN_LOG_INIT_DEBUG   CMN_LOG(CMN_LOG_LEVEL_INIT_DEBUG)
#define CMN_LOG_INIT_ERROR   CMN_LOG(CMN_LOG_LEVEL_INIT_ERROR) << CMN_LOG_DETAILS << " "

Macros defined to use CMN_LOG for a given level of detail.

#define CMN_LOG_INIT_VERBOSE   CMN_LOG(CMN_LOG_LEVEL_INIT_VERBOSE)
#define CMN_LOG_INIT_WARNING   CMN_LOG(CMN_LOG_LEVEL_INIT_WARNING)
#define CMN_LOG_RUN_DEBUG   CMN_LOG(CMN_LOG_LEVEL_RUN_DEBUG)
#define CMN_LOG_RUN_ERROR   CMN_LOG(CMN_LOG_LEVEL_RUN_ERROR) << CMN_LOG_DETAILS << " "
#define CMN_LOG_RUN_VERBOSE   CMN_LOG(CMN_LOG_LEVEL_RUN_VERBOSE)
#define CMN_LOG_RUN_WARNING   CMN_LOG(CMN_LOG_LEVEL_RUN_WARNING)