Miind
The Log utilities provided by miind

This page contains the following sections:

  1. Introduction
  2. Advanced use of logging
  3. The Log Macro
  4. Provided Debug levels

Introduction

To log a message in miind use the following macro:

LOG(utilities::logWARNING)<<"blub: "<<42;

This would then log a message of the level logWARNING if the current reporting level is higher that logWARNING. Otherwise the logging would be ignored. As this check is done at compile time you pay only for log messages if they are actually printed.

Advanced use of logging

The default logging level is defined by the flag DEBUGLEVEL then everything is printed to the log. To change the reporting level of the log class the following code is needed:

This code would set the reporting level to logWARNING

In the default version log messages are printed to std::cerr. To print the log messages into a log file the following code is needed:

std::shared_ptr<std::ostream> pStream( new std::ofstream("MYLOGFILENAME"));
if (!pStream){
throw utilities::Exception("cannot open log file.");
}

This code would redirect the log messages to the file with the name MYLOGFILENAME.

The Log Macro

The macro allows easier generation of log messages. It also improves the efficiency significantly as the checks are conducted at compile time.

Attention
do not pass functions to this macro. This is due to the problematic macro expansion. For example this:
LOG(logERROR)<<getNumber();

is forbidden. Please use then instead a temporary variable:

int number = getNumber()
LOG(logERROR)<<number;

or alternatively write it the following way:

;
}else{
utilities::Log().writeReport(level)<<getNumber;
}

However try to use the macro with temporary variables.

Provided Debug levels

logERROR
Only use this for real error messages, as these are always logged.
logWARNING
use this for warnings messages.
logINFO
Use this for information messages
logDEBUG
Use this for very important debug messages
logDEBUG1
Use this for important debug messages
logDEBUG2
Use this for not so important debug messages
logDEBUG3
Use this for not important debug messages
logDEBUG4
Use this for for every debug detail messages