GGS(GenericGEANT4Simulation)Software  2.99.0
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations 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 GGSCOUT_BACKEND   std::cout
 Smart log macro. It writes on stdout only if the specified verbosity level is lesser than the maximum one (GGSSmartLog::verboseLevel). More...
 
#define GGSCOUT(level)
 
#define GGSCCOUT(level)
 Smart log utility which prints no header at the beginning of the line. More...
 
#define GGSENDL   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 ()
 Unmutes 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 GGSCOUT.
 
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 GGSCCOUT (   level)
Value:
if (GGSSmartLog::verboseLevel >= GGSSmartLog::level) \
GGSCOUT_BACKEND << std::setw(GGSSmartLog::maxRoutineNameLength + 13) << " "
#define GGSCOUT_BACKEND
Smart log macro. It writes on stdout only if the specified verbosity level is lesser than the maximum...
Definition: GGSSmartLog.h:100

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

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

static const std::string routineName("dummyFunction"); GGSCOUT(ERROR) << "Error reasons:" << GGSENDL; GGSCCOUT(ERROR) << "- Reason 1" << GGSENDL; GGSCCOUT(ERROR) << "- Reason 2" << GGSENDL;

will print:

[dummyFunction] ERROR Error reasons:

  • Reason 1
  • Reason 2

Definition at line 126 of file GGSSmartLog.h.

#define GGSCOUT (   level)
Value:
if (GGSSmartLog::verboseLevel >= GGSSmartLog::level) \
<< std::setw(GGSSmartLog::maxRoutineNameLength + 3) << std::left \
<< std::string("[").append(GGSSmartLog::Format(routineName, GGSSmartLog::maxRoutineNameLength)).append("] ") \
<< std::setw(10) << GGSSmartLog::levelNames[GGSSmartLog::level]
#define GGSCOUT_BACKEND
Smart log macro. It writes on stdout only if the specified verbosity level is lesser than the maximum...
Definition: GGSSmartLog.h:100

Definition at line 102 of file GGSSmartLog.h.

#define GGSCOUT_BACKEND   std::cout

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") GGSCOUT(ERROR) << "This is an error message." << GGSENDL;}

will print:

[dummyFunction] ERROR This is an error message.

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

Definition at line 100 of file GGSSmartLog.h.

#define GGSENDL   std::endl

Alias for std::endl.

Definition at line 131 of file GGSSmartLog.h.