EventAnalysis  1.0.0
Namespaces | Macros | Enumerations | Functions | Variables
SmartLog.h File Reference
#include <iomanip>
#include <iostream>

Go to the source code of this file.

Namespaces

 EA
 IncludeFileExc.h IncludeFileExc class declaration.
 
 EA::SmartLog
 

Macros

#define COUT(level)
 
#define CCOUT(level)
 Smart log utility which prints no header at the beginning of the line. More...
 
#define ENDL   std::endl
 

Enumerations

enum  EA::SmartLog::VerboseLevel {
  EA::SmartLog::VerboseLevel::SILENT = 0, EA::SmartLog::VerboseLevel::ERROR = 1, EA::SmartLog::VerboseLevel::WARNING = 2, EA::SmartLog::VerboseLevel::INFO = 3,
  EA::SmartLog::VerboseLevel::DEBUG = 4, EA::SmartLog::VerboseLevel::DEEPDEB = 5
}
 

Functions

bool EA::SmartLog::operator> (const VerboseLevel &vl1, const VerboseLevel &vl2)
 
std::string EA::SmartLog::Format (const std::string &str, size_t maxLength)
 Format a string so that its length is less or equal to maxLength. More...
 
void EA::SmartLog::MuteOutput ()
 Mutes the console output. More...
 
void EA::SmartLog::UnmuteOutput ()
 Unmutes the console output. More...
 

Variables

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

Detailed Description

Some utilities for logs with support for different verbosity levels.

Macro Definition Documentation

◆ CCOUT

#define CCOUT (   level)
Value:
if (EA::SmartLog::verboseLevel >= EA::SmartLog::VerboseLevel::level) \
std::cout << std::setfill(' ') << std::setw(EA::SmartLog::maxRoutineNameLength + 13) << " "
VerboseLevel verboseLevel
The maximum desired verbosity.
Definition: SmartLog.cpp:19
int maxRoutineNameLength
The maximum length for the printed routine name.
Definition: SmartLog.cpp:20

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

◆ COUT

#define COUT (   level)
Value:
if (EA::SmartLog::verboseLevel >= EA::SmartLog::VerboseLevel::level) \
std::cout \
<< std::setfill(' ') << std::setw(EA::SmartLog::maxRoutineNameLength + 3) << std::left \
<< std::string("[").append(EA::SmartLog::Format(routineName, EA::SmartLog::maxRoutineNameLength)).append("] ") \
<< std::setw(10) << EA::SmartLog::levelNames[static_cast<int>(EA::SmartLog::VerboseLevel::level)]
std::string Format(const std::string &str, size_t maxLength)
Format a string so that its length is less or equal to maxLength.
Definition: SmartLog.cpp:22
VerboseLevel verboseLevel
The maximum desired verbosity.
Definition: SmartLog.cpp:19
const char * levelNames[6]
Name of verbosity levels, which will be printed on stdout at each call of COUT.
Definition: SmartLog.cpp:18
int maxRoutineNameLength
The maximum length for the printed routine name.
Definition: SmartLog.cpp:20

Smart log function. It writes on stdout only if the specified verbosity level is lesser than the maximum one (SmartLog::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 SmartLog::verboseLevel has been set to ERROR or higher.

◆ ENDL

#define ENDL   std::endl

Alias for std::endl.