GGS(GenericGEANT4Simulation)Software  2.7.0
 All Data Structures Namespaces Files Functions Variables Typedefs Macros
Macros | Enumerations | Functions | Variables
GGSSmartLog.h File Reference
#include <iomanip>
#include <iostream>
Include dependency graph for GGSSmartLog.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define COUT(level)
 Smart log macro. It writes on stdout only if the specified verbosity level is lesser than the maximum one (GGSSmartLog::verboseLevel). More...
 
#define CCOUT(level)
 Smart log utility which prints no header at the beginning of the line. More...
 
#define ENDL   std::endl
 

Enumerations

enum  {
  SILENT, ERROR, WARNING, INFO,
  DEBUG, DEEPDEB
}
 

Functions

const std::string & GGSSmartLog::Format (const std::string &str, unsigned int maxLength)
 Format a string so that its length is less or equal to maxLength. More...
 
void GGSSmartLog::MuteOutput ()
 Mutes the console output. More...
 
void GGSSmartLog::UnmuteOutput ()
 Unutes the console output. More...
 

Variables

const char * GGSSmartLog::levelNames [6] = {"", "ERROR", "WARNING", "INFO", "DEBUG", "DEEPDEB"}
 Name of verbosity levels, which will be printed on stdout at each call of COUT.
 
int GGSSmartLog::verboseLevel = INFO
 The maximum desired verbosity.
 
int GGSSmartLog::maxRoutineNameLength = 30
 The maximum length for the printed routine name.
 

Detailed Description

Some utilities for logs with support for different verbosity levels.

Definition in file GGSSmartLog.h.

Macro Definition Documentation

#define CCOUT (   level)
Value:
if (GGSSmartLog::verboseLevel >= GGSSmartLog::level) \
std::cout << std::setw(GGSSmartLog::maxRoutineNameLength + 13) << " "

Smart log utility which prints no header at the beginning of the line.

This macro is useful to continue the output of the standard COUT on subsequent lines without repeating the header at each line. For example:

static const std::string routineName("dummyFunction"); COUT(ERROR) << "Error reasons:" << ENDL; CCOUT(ERROR) << "- Reason 1" << ENDL; CCOUT(ERROR) << "- Reason 2" << ENDL;

will print:

[dummyFunction] ERROR Error reasons:

  • Reason 1
  • Reason 2

Definition at line 100 of file GGSSmartLog.h.

#define COUT (   level)
Value:
if (GGSSmartLog::verboseLevel >= GGSSmartLog::level) \
std::cout \
<< std::setw(GGSSmartLog::maxRoutineNameLength + 3) << std::left \
<< std::string("[").append(GGSSmartLog::Format(routineName, GGSSmartLog::maxRoutineNameLength)).append("] ") \
<< std::setw(10) << GGSSmartLog::levelNames[GGSSmartLog::level]

Smart log macro. It writes on stdout only if the specified verbosity level is lesser than the maximum one (GGSSmartLog::verboseLevel).

It requires to define a routineName string variable inside every context from which it is called. For example:

void dummyFunction{ static const std::string routineName("dummyFunction") COUT(ERROR) << "This is an error message." << ENDL;}

will print:

[dummyFunction] ERROR This is an error message.

only if GGSSmartLog::verboseLevel has been set to ERROR or higher.

Definition at line 76 of file GGSSmartLog.h.

#define ENDL   std::endl

Alias for std::endl.

Definition at line 105 of file GGSSmartLog.h.