Hammer
1.0.0
Helicity Amplitude Module for Matrix Element Reweighting
|
Logging class. More...
#include <Logging.hh>
Public Types | |
Type definitions | |
enum | Level { TRACE = 0, DEBUG = 10, INFO = 20, WARN = 30, WARNING = 30, ERROR = 40, CRITICAL = 50, ALWAYS = 50 } |
Log priority levels. More... | |
using | LogMap = std::map< std::string, std::unique_ptr< Log >> |
Typedef for a collection of named logs. More... | |
using | LevelMap = std::map< std::string, int > |
Typedef for a collection of named log levels. More... | |
using | WarningCountMap = std::map< std::string, int > |
Typedef for a counting the number of warnings in order to turn off warnings above a certain threshold. More... | |
using | ColorCodes = std::map< int, std::string > |
Typedef for a collection of shell color codes, accessed by log level. More... | |
Public Member Functions | |
Non-static public interface | |
bool | isActive (int level) const |
Will this log level produce output on this logger at the moment? More... | |
void | trace (const std::string &message) |
log a trace message More... | |
void | debug (const std::string &message) |
log a debug message More... | |
void | info (const std::string &message) |
log an information message More... | |
void | warn (const std::string &message) |
log a warning message More... | |
void | error (const std::string &message) |
log an error message More... | |
int | getLevel () const |
Get the priority level of this logger. More... | |
Static Public Member Functions | |
Public static interface | |
static Log & | getLog (const std::string &name) |
Get a logger with the given name. More... | |
static void | setLevel (const std::string &name, int level) |
Set the log levels. More... | |
static void | setLevels (const LevelMap &logLevels) |
Set the log levels all at once. More... | |
static void | setShowTimestamp (bool showTime=true) |
toggle whether to include the timestamp in a logging message More... | |
static void | setShowLevel (bool showLevel=true) |
toggle whether to display the verbosity level in a logging message More... | |
static void | setShowLoggerName (bool showName=true) |
toggle whether to display the logger name in a logging message More... | |
static void | setUseColors (bool useColors=true) |
toggle whether to display colorful logging messages More... | |
static void | setWarningMaxCount (const std::string &name, int maxCount) |
set the maximum number of warnings for a given logger More... | |
static void | resetWarningCounters () |
reset the warning counters for all loggers More... | |
Protected Member Functions | |
Constructors | |
Log (const std::string &name) | |
Constructor by name. More... | |
Log (const std::string &name, int level) | |
Constructor by name and verbosity level. More... | |
Log (const std::string &name, int level, int maxCount) | |
Constructor by name, verbosity level and warning count. More... | |
Protected Attributes | |
std::unique_ptr< std::ostream > const | _nostream |
A null output stream, used for piping discarded output to nowhere. More... | |
Private Attributes | |
Data members | |
int | _level |
Threshold level for this logger. More... | |
int | _warnCounter |
number of warnings issued by this logger. More... | |
int | _maxWarning |
maximum number of warnings for this logger. More... | |
std::string | _name |
This logger's name. More... | |
Friends | |
std::ostream & | operator<< (Log &log, int level) |
Streaming output to a logger must have a Level/int as its first argument. More... | |
Static data members access functions | |
static bool | showTimestamp = false |
Show timestamp? More... | |
static bool | showLogLevel = true |
Show log level? More... | |
static bool | showLoggerName = true |
Show logger name? More... | |
static bool | useShellColors = true |
Use shell colour escape codes? More... | |
static LogMap & | existingLogs () |
A static map of existing logs: we don't make more loggers than necessary. More... | |
static LevelMap & | defaultLevels () |
A static map of default log levels. More... | |
static WarningCountMap & | defaultMaxWarnings () |
A static map for counting how many warnings have been issued for each logger. More... | |
static ColorCodes & | colorCodes () |
A static map of shell color codes for the log levels. More... | |
static std::string & | endColorCode () |
Shell color code for the end of the log levels. More... | |
static std::mutex & | displayLock () |
Mutex to access screen (protected because external streaming operator uses it) More... | |
static std::mutex & | lock () |
Mutex to modify global elements (protected because external streaming operator uses it) More... | |
Internal methods | |
static void | updateLevels () |
updates the verbosity levels of all the loggers More... | |
static void | updateCounters () |
updates the max warning numbers of all the loggers More... | |
static Level | getLevelFromName (const std::string &level) |
Get a log level enum from a string. More... | |
static std::string | getLevelName (int level) |
Get the std::string representation of a log level. More... | |
std::string | getColorCode (int level) |
provide the escape string for the color associated to a give log level More... | |
int | getMaxWarning () const |
Get the maximum number of warnings for this logger. More... | |
Log & | setLevel (int level) |
Set the priority level of this logger. More... | |
Log & | setWarnCount (int numCount) |
Set the maximum number of warnings of this logger. More... | |
std::string | getName () const |
Get the name of this logger. More... | |
Log & | setName (const std::string &name) |
Set the name of this logger. More... | |
void | log (int level, const std::string &message) |
Write a message at a particular level. More... | |
std::string | formatMessage (int level, const std::string &message) |
Turn a message string into the current log format. More... | |
Logging class.
Defines basic interface for logging and displaying messages Manages a static dictionary of different named loggers
Definition at line 33 of file Logging.hh.
using Hammer::Log::ColorCodes = std::map<int, std::string> |
Typedef for a collection of shell color codes, accessed by log level.
Definition at line 59 of file Logging.hh.
using Hammer::Log::LevelMap = std::map<std::string, int> |
Typedef for a collection of named log levels.
Definition at line 53 of file Logging.hh.
using Hammer::Log::LogMap = std::map<std::string, std::unique_ptr<Log>> |
Typedef for a collection of named logs.
Definition at line 50 of file Logging.hh.
using Hammer::Log::WarningCountMap = std::map<std::string, int> |
Typedef for a counting the number of warnings in order to turn off warnings above a certain threshold.
Definition at line 56 of file Logging.hh.
enum Hammer::Log::Level |
Log priority levels.
Enumerator | |
---|---|
TRACE | |
DEBUG | |
INFO | |
WARN | |
WARNING | |
ERROR | |
CRITICAL | |
ALWAYS |
Definition at line 45 of file Logging.hh.
|
protected |
|
protected |
Constructor by name and verbosity level.
[in] | name | logger name |
[in] | level | verbosity level |
Definition at line 99 of file Logging.cc.
|
protected |
Constructor by name, verbosity level and warning count.
[in] | name | logger name |
[in] | level | verbosity level |
[in] | maxCount | upper limit on the number of warnings |
Definition at line 102 of file Logging.cc.
|
staticprivate |
A static map of shell color codes for the log levels.
Definition at line 39 of file Logging.cc.
|
inline |
log a debug message
[in] | message | the message text |
Definition at line 288 of file Logging.hh.
|
staticprivate |
A static map of default log levels.
Definition at line 29 of file Logging.cc.
|
staticprivate |
A static map for counting how many warnings have been issued for each logger.
Definition at line 34 of file Logging.cc.
|
staticprotected |
Mutex to access screen (protected because external streaming operator uses it)
Definition at line 54 of file Logging.cc.
|
staticprivate |
Shell color code for the end of the log levels.
Definition at line 44 of file Logging.cc.
|
inline |
log an error message
[in] | message | the message text |
Definition at line 306 of file Logging.hh.
|
staticprivate |
A static map of existing logs: we don't make more loggers than necessary.
Definition at line 24 of file Logging.cc.
|
protected |
Turn a message string into the current log format.
[in] | level | the log level |
[in] | message | the log message |
Definition at line 274 of file Logging.cc.
|
protected |
provide the escape string for the color associated to a give log level
[in] | level | the log level |
Definition at line 216 of file Logging.cc.
|
inline |
Get the priority level of this logger.
Definition at line 312 of file Logging.hh.
|
staticprotected |
Get a log level enum from a string.
[in] | level | the level name |
Definition at line 249 of file Logging.cc.
|
staticprotected |
Get the std::string representation of a log level.
[in] | level | the level enum |
Definition at line 190 of file Logging.cc.
|
static |
Get a logger with the given name.
The level will be taken from the "requestedLevels" static map or will be INFO by default.
[in] | name | the name of the logger |
Definition at line 139 of file Logging.cc.
|
inlineprotected |
Get the maximum number of warnings for this logger.
Definition at line 210 of file Logging.hh.
|
inlineprotected |
|
inline |
log an information message
[in] | message | the message text |
Definition at line 294 of file Logging.hh.
|
inline |
Will this log level produce output on this logger at the moment?
Definition at line 276 of file Logging.hh.
|
staticprotected |
Mutex to modify global elements (protected because external streaming operator uses it)
Definition at line 49 of file Logging.cc.
|
protected |
Write a message at a particular level.
[in] | level | the log level |
[in] | message | the log message |
Definition at line 310 of file Logging.cc.
|
static |
reset the warning counters for all loggers
Definition at line 132 of file Logging.cc.
|
static |
Set the log levels.
[in] | name | the name of the logger |
[in] | level | the verbosity level |
Definition at line 105 of file Logging.cc.
|
inlineprotected |
Set the priority level of this logger.
[in] | level | the verbosity level |
Definition at line 217 of file Logging.hh.
|
static |
Set the log levels all at once.
[in] | logLevels | the verbosity level map |
Definition at line 113 of file Logging.cc.
|
inlineprotected |
Set the name of this logger.
[in] | name | the logger name |
Definition at line 251 of file Logging.hh.
|
inlinestatic |
toggle whether to display the verbosity level in a logging message
[in] | showLevel | the flag value |
Definition at line 141 of file Logging.hh.
|
inlinestatic |
toggle whether to display the logger name in a logging message
[in] | showName | the flag value |
Definition at line 148 of file Logging.hh.
|
inlinestatic |
toggle whether to include the timestamp in a logging message
[in] | showTime | the flag value |
Definition at line 134 of file Logging.hh.
|
inlinestatic |
toggle whether to display colorful logging messages
[in] | useColors | the flag value |
Definition at line 155 of file Logging.hh.
|
inlineprotected |
Set the maximum number of warnings of this logger.
[in] | numCount | the number of warnings |
Definition at line 226 of file Logging.hh.
|
static |
set the maximum number of warnings for a given logger
[in] | name | the logger name |
[in] | maxCount | the maximum number of warnings |
Definition at line 124 of file Logging.cc.
|
inline |
log a trace message
[in] | message | the message text |
Definition at line 282 of file Logging.hh.
|
staticprotected |
updates the max warning numbers of all the loggers
Definition at line 76 of file Logging.cc.
|
staticprotected |
updates the verbosity levels of all the loggers
Definition at line 66 of file Logging.cc.
|
inline |
log a warning message
[in] | message | the message text |
Definition at line 300 of file Logging.hh.
|
friend |
Streaming output to a logger must have a Level/int as its first argument.
[in] | log | the logger |
[in] | level | the log level |
Definition at line 334 of file Logging.cc.
|
private |
Threshold level for this logger.
Definition at line 329 of file Logging.hh.
|
private |
maximum number of warnings for this logger.
Definition at line 335 of file Logging.hh.
|
private |
This logger's name.
Definition at line 338 of file Logging.hh.
|
protected |
A null output stream, used for piping discarded output to nowhere.
Definition at line 321 of file Logging.hh.
|
private |
number of warnings issued by this logger.
Definition at line 332 of file Logging.hh.
|
staticprivate |
Show logger name?
Definition at line 95 of file Logging.hh.
|
staticprivate |
Show log level?
Definition at line 92 of file Logging.hh.
|
staticprivate |
Show timestamp?
Definition at line 89 of file Logging.hh.
|
staticprivate |
Use shell colour escape codes?
Definition at line 98 of file Logging.hh.