EventAnalysis  1.0.0
SmartLog.h
Go to the documentation of this file.
1 /*
2  * SmartLog.h
3  *
4  * Created on: 21 Nov 2014
5  * Author: Nicola Mori
6  */
7 
10 #ifndef SMARTLOG_H_
11 #define SMARTLOG_H_
12 
13 #include <iomanip>
14 #include <iostream>
15 
16 namespace EA {
17 
18 namespace SmartLog {
26 enum class VerboseLevel { SILENT = 0, ERROR = 1, WARNING = 2, INFO = 3, DEBUG = 4, DEEPDEB = 5 };
27 inline bool operator>(const VerboseLevel &vl1, const VerboseLevel &vl2) {
28  return (static_cast<int>(vl1) > static_cast<int>(vl2));
29 }
30 
31 extern const char *levelNames[6];
33 extern int maxRoutineNameLength;
34 
44 extern std::string Format(const std::string &str, size_t maxLength);
45 
52 extern void MuteOutput();
53 
59 extern void UnmuteOutput();
60 
61 } // namespace SmartLog
62 
63 } // namespace EA
64 
88 #define COUT(level) \
89  if (EA::SmartLog::verboseLevel >= EA::SmartLog::VerboseLevel::level) \
90  std::cout \
91  << std::setfill(' ') << std::setw(EA::SmartLog::maxRoutineNameLength + 3) << std::left \
92  << std::string("[").append(EA::SmartLog::Format(routineName, EA::SmartLog::maxRoutineNameLength)).append("] ") \
93  << std::setw(10) << EA::SmartLog::levelNames[static_cast<int>(EA::SmartLog::VerboseLevel::level)]
94 
112 #define CCOUT(level) \
113  if (EA::SmartLog::verboseLevel >= EA::SmartLog::VerboseLevel::level) \
114  std::cout << std::setfill(' ') << std::setw(EA::SmartLog::maxRoutineNameLength + 13) << " "
115 
117 #define ENDL std::endl
118 
119 #endif /* SMARTLOG_H_ */
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
IncludeFileExc.h IncludeFileExc class declaration.
Definition: Algorithm.h:21
VerboseLevel
Definition: SmartLog.h:26
int maxRoutineNameLength
The maximum length for the printed routine name.
Definition: SmartLog.cpp:20
void MuteOutput()
Mutes the console output.
Definition: SmartLog.cpp:57
void UnmuteOutput()
Unmutes the console output.
Definition: SmartLog.cpp:74
bool operator>(const VerboseLevel &vl1, const VerboseLevel &vl2)
Definition: SmartLog.h:27