cisst-saw
Loading...
Searching...
No Matches
cmnLogger Class Reference

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

#include <cmnLogger.h>

Public Types

typedef cmnLODMultiplexerStreambuf< char > StreamBufType

Static Public Member Functions

static cmnLoggerInstance (void)
static void SetMask (cmnLogMask mask)
static void CISST_DEPRECATED SetLoD (cmnLogMask mask)
static cmnLogMask GetMask (void)
static cmnLogMask CISST_DEPRECATED GetLoD (void)
static void SetMaskFunction (cmnLogMask mask)
static cmnLogMask GetMaskFunction (void)
static bool SetMaskClass (const std::string &className, cmnLogMask mask)
static bool SetMaskClassAll (cmnLogMask mask)
static bool SetMaskClassMatching (const std::string &stringToMatch, cmnLogMask mask)
static StreamBufTypeGetMultiplexer (void)
static void HaltDefaultLog (void)
static void ResumeDefaultLog (cmnLogMask newLoD=CMN_LOG_ALLOW_DEFAULT)
static void SetMaskDefaultLog (cmnLogMask newLoD=CMN_LOG_ALLOW_DEFAULT)
static void AddChannel (std::ostream &outputStream, cmnLogMask mask=CMN_LOG_ALLOW_ALL)
static void AddChannelToStdOut (cmnLogMask mask=CMN_LOG_ALLOW_ERRORS_AND_WARNINGS)
static void AddChannelToStdErr (cmnLogMask mask=CMN_LOG_ALLOW_ERRORS_AND_WARNINGS)
static void RemoveChannel (std::ostream &outputStream)
static const char * ExtractFileName (const char *file)
static void Kill (void)
static bool SetDefaultLogFileName (const std::string &defaultLogFileName)
static std::string GetDefaultLogFileName (void)
static bool IsCreated ()

Protected Member Functions

 cmnLogger (const std::string &defaultLogFileName=DefaultLogFileName)

Detailed Description

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

cmnLogger is defined as a singleton, i.e. there is only one instance of cmnLogger. This unique object maintains the data required for the cisst logging system. The design of the logging system relies on:

  • Human readable messages are associated to a Level of Detail.
  • The messages are sent and filtered based on their level of detail. The macros used to send the messages actually check if the message is to be sent or not before creating them in order to improve performances (see CMN_LOG_CLASS and CMN_LOG).
  • The messages are sent to a multiplexer owned by cmnLogger. This multiplexer allows to send the message (along with their level of detail) to multiple output streams.

To filter the messages, the user can use:

  • The global log mask defined in cmnLogger. Any message with a level of detail incompatible with overall log mask will be ignored (at minimal execution time cost). This mask is used by CMN_LOG_CLASS and CMN_LOG. To modify the overall mask, use cmnLogger::SetMask(newMask).
  • Each class relies on its own log mask. This allows to tune the log based on the user's needs. One can for example allow all the messages (from errors to debug) from a given class and block all the messages from every other class. As for the overall log mask, if a message's level of detail is incompatible with the class mask, it will be ignored (at minimal execution time cost). This log mask is used only be CMN_LOG_CLASS. To modify a class log mask, use either the logger with cmnLogger::SetMaskClass("className", newMask), cmnLogger::SetMaskClassMatching("cmn", newMask), cmnLogger::SetMaskClassAll(newMask) or the class services with object.Services()->SetLogMask(newMask).
  • The output streams masks. Each output stream has its own log mask and will stream only the messages with a compatible level of detail. This allows for example to log everything to a file while printing only the high priority ones to std::cout. To set the level of detail of an output stream, use cmnLogger::AddChannel(newStream, newMask).
See also
cmnClassRegister cmnClassServicesBase cmnLODOutputMultiplexer

Member Typedef Documentation

◆ StreamBufType

Type used to define the logging level of detail.

Constructor & Destructor Documentation

◆ cmnLogger()

cmnLogger::cmnLogger ( const std::string & defaultLogFileName = DefaultLogFileName)
protected

Constructor. The only constructor must be private in order to ensure that the class register is a singleton.

Member Function Documentation

◆ AddChannel()

void cmnLogger::AddChannel ( std::ostream & outputStream,
cmnLogMask mask = CMN_LOG_ALLOW_ALL )
inlinestatic

Add an output stream to the logger. The level of detail provided is used to filter the messages, i.e. any message with a level of detail higher than the level associated to the output stream will not be streamed.

◆ AddChannelToStdErr()

void cmnLogger::AddChannelToStdErr ( cmnLogMask mask = CMN_LOG_ALLOW_ERRORS_AND_WARNINGS)
inlinestatic

Add std::cerr output stream to the logger. Useful when calling from Python, where redirecting sys.stderr to std::cerr is nontrivial.

◆ AddChannelToStdOut()

void cmnLogger::AddChannelToStdOut ( cmnLogMask mask = CMN_LOG_ALLOW_ERRORS_AND_WARNINGS)
inlinestatic

Add std::cout output stream to the logger. Useful when calling from Python, where redirecting sys.stdout to std::cout is nontrivial.

◆ ExtractFileName()

const char * cmnLogger::ExtractFileName ( const char * file)
static

◆ GetDefaultLogFileName()

std::string cmnLogger::GetDefaultLogFileName ( void )
inlinestatic

Returns name of default log file.

◆ GetLoD()

cmnLogMask CISST_DEPRECATED cmnLogger::GetLoD ( void )
inlinestatic

◆ GetMask()

cmnLogMask cmnLogger::GetMask ( void )
inlinestatic

Get the global mask used to filter the log messages.

Returns
The global mask used to filter the log.
See also
GetMaskInstance

◆ GetMaskFunction()

cmnLogMask cmnLogger::GetMaskFunction ( void )
inlinestatic

Get the function mask used to filter the log messages.

Returns
The function mask used to filter the log.
See also
GetMaskInstance

◆ GetMultiplexer()

StreamBufType * cmnLogger::GetMultiplexer ( void )
inlinestatic

Returns the cmnLODMultiplexerStreambuf directly. This allows manipulation of the streambuffer for operations such as adding or deleting channels for the stream..

Returns
cmnLODMultiplexerStreambuf<char>* The Streambuffer.
See also
GetMultiplexerInstance

◆ HaltDefaultLog()

void cmnLogger::HaltDefaultLog ( void )
inlinestatic

Disable the default log file "cisstLog.txt". This method removes the default log from the output list of the multiplexer but doesn't close the default log file.

◆ Instance()

cmnLogger * cmnLogger::Instance ( void )
static

The log is instantiated as a singleton. To access the unique instantiation, one needs to use this static method. The instantiated log is created at the first call of this method since it is a static variable declared in this method's scope.

Returns
A pointer to the logger.

◆ IsCreated()

bool cmnLogger::IsCreated ( )
inlinestatic

Returns true if cmnLogger instance has been created (i.e., constructor called).

◆ Kill()

void cmnLogger::Kill ( void )
inlinestatic

Kill the logger. Set all masks to disable logs and remove all output streams.

◆ RemoveChannel()

void cmnLogger::RemoveChannel ( std::ostream & outputStream)
inlinestatic

◆ ResumeDefaultLog()

void cmnLogger::ResumeDefaultLog ( cmnLogMask newLoD = CMN_LOG_ALLOW_DEFAULT)
inlinestatic

Resume the default log file. By default, the log is enabled (this is the default behavior of the cmnLogger constructor) but this can be halted by using HaltDefaultLog(). Using ResumeDefaultLog() allows to resume the log to "cisstLog.txt" without losing previous logs.

◆ SetDefaultLogFileName()

bool cmnLogger::SetDefaultLogFileName ( const std::string & defaultLogFileName)
static

Set the name of the default log file. This function must be called before the cmnLogger instance is created.

Returns
true if the default log file name can be set (i.e., cmnLogger instance not yet created); false otherwise.

◆ SetLoD()

void CISST_DEPRECATED cmnLogger::SetLoD ( cmnLogMask mask)
inlinestatic

◆ SetMask()

void cmnLogger::SetMask ( cmnLogMask mask)
inlinestatic

Set the global mask used to filter the log messages.

Parameters
maskThe overall mask used to filter the log.
See also
SetMaskInstance

◆ SetMaskClass()

bool cmnLogger::SetMaskClass ( const std::string & className,
cmnLogMask mask )
static

Specify the log mask for a specific class. See cmnClassRegister::SetLogMaskClass.

Parameters
classNameThe name of the class
maskThe log mask to be applied
Returns
bool True if the class is registered.

◆ SetMaskClassAll()

bool cmnLogger::SetMaskClassAll ( cmnLogMask mask)
static

Specify the log mask for all registered classes. See cmnClassRegister::SetLogMaskClassAll.

Parameters
maskThe log mask to be applied
Returns
bool True if there is at least one class mask was modified

◆ SetMaskClassMatching()

bool cmnLogger::SetMaskClassMatching ( const std::string & stringToMatch,
cmnLogMask mask )
static

Specify the log mask for all classes with a name matching a given string. See cmnClassRegister::SetLogMaskClassMatching.

Parameters
stringToMatchA string found in class names (e.g. "cmn")
maskThe log mask to be applied
Returns
bool True if there is at least one class LoD was modified

◆ SetMaskDefaultLog()

void cmnLogger::SetMaskDefaultLog ( cmnLogMask newLoD = CMN_LOG_ALLOW_DEFAULT)
inlinestatic

Set a new mask for the default log file. This method uses HaltDefaultLog followed by ResumeDefaultLog.

◆ SetMaskFunction()

void cmnLogger::SetMaskFunction ( cmnLogMask mask)
inlinestatic

Set the "function" mask used to filter the log messages.

Parameters
maskThe function mask used to filter the log.
See also
SetMaskFunctionInstance

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