13 #ifndef HAMMER_LOGGING_HH
14 #define HAMMER_LOGGING_HH
50 using LogMap = std::map<std::string, std::unique_ptr<Log>>;
108 static std::mutex&
lock();
121 static Log&
getLog(
const std::string& name);
126 static void setLevel(
const std::string& name,
int level);
135 std::lock_guard<std::mutex> guard(
lock());
142 std::lock_guard<std::mutex> guard(
lock());
149 std::lock_guard<std::mutex> guard(
lock());
156 std::lock_guard<std::mutex> guard(
lock());
177 Log(
const std::string& name);
182 Log(
const std::string& name,
int level);
188 Log(
const std::string& name,
int level,
int maxCount);
218 std::lock_guard<std::mutex> guard(
lock());
227 std::lock_guard<std::mutex> guard(
lock());
252 std::lock_guard<std::mutex> guard(
lock());
260 void log(
int level,
const std::string& message);
266 std::string
formatMessage(
int level,
const std::string& message);
282 void trace(
const std::string& message) {
288 void debug(
const std::string& message) {
294 void info(
const std::string& message) {
300 void warn(
const std::string& message) {
306 void error(
const std::string& message) {
356 #define MSG_LVL(lvl, x) \
358 if (getLog().isActive(lvl)) { \
359 getLog() << lvl << x << std::endl; \
363 #define MSG_TRACE(x) MSG_LVL(Log::TRACE, x)
364 #define MSG_DEBUG(x) MSG_LVL(Log::DEBUG, x)
365 #define MSG_INFO(x) MSG_LVL(Log::INFO, x)
366 #define MSG_WARNING(x) MSG_LVL(Log::WARNING, x)
367 #define MSG_ERROR(x) MSG_LVL(Log::ERROR, x)
Log & setLevel(int level)
Set the priority level of this logger.
void error(const std::string &message)
log an error message
static void setShowLevel(bool showLevel=true)
toggle whether to display the verbosity level in a logging message
static std::string & endColorCode()
Shell color code for the end of the log levels.
int _level
Threshold level for this logger.
static WarningCountMap & defaultMaxWarnings()
A static map for counting how many warnings have been issued for each logger.
std::map< std::string, std::unique_ptr< Log >> LogMap
Typedef for a collection of named logs.
static void setShowTimestamp(bool showTime=true)
toggle whether to include the timestamp in a logging message
Log & setWarnCount(int numCount)
Set the maximum number of warnings of this logger.
void trace(const std::string &message)
log a trace message
std::unique_ptr< std::ostream > const _nostream
A null output stream, used for piping discarded output to nowhere.
YAML::Emitter & operator<<(YAML::Emitter &out, const ProcessDefinitions &s)
static void setShowLoggerName(bool showName=true)
toggle whether to display the logger name in a logging message
static bool showTimestamp
Show timestamp?
static void updateLevels()
updates the verbosity levels of all the loggers
void warn(const std::string &message)
log a warning message
static void resetWarningCounters()
reset the warning counters for all loggers
std::string getColorCode(int level)
provide the escape string for the color associated to a give log level
static LevelMap & defaultLevels()
A static map of default log levels.
static Level getLevelFromName(const std::string &level)
Get a log level enum from a string.
std::string getName() const
Get the name of this logger.
bool isActive(int level) const
Will this log level produce output on this logger at the moment?
static Log & getLog(const std::string &name)
Get a logger with the given name.
Hammer exception definitions.
int getMaxWarning() const
Get the maximum number of warnings for this logger.
Log & setName(const std::string &name)
Set the name of this logger.
static bool showLogLevel
Show log level?
int _warnCounter
number of warnings issued by this logger.
std::map< std::string, int > LevelMap
Typedef for a collection of named log levels.
void info(const std::string &message)
log an information message
std::string formatMessage(int level, const std::string &message)
Turn a message string into the current log format.
static void updateCounters()
updates the max warning numbers of all the loggers
void log(int level, const std::string &message)
Write a message at a particular level.
static std::mutex & lock()
Mutex to modify global elements (protected because external streaming operator uses it) ...
std::map< int, std::string > ColorCodes
Typedef for a collection of shell color codes, accessed by log level.
static void setLevels(const LevelMap &logLevels)
Set the log levels all at once.
static std::string getLevelName(int level)
Get the std::string representation of a log level.
std::map< std::string, int > WarningCountMap
Typedef for a counting the number of warnings in order to turn off warnings above a certain threshold...
Level
Log priority levels.
static void setWarningMaxCount(const std::string &name, int maxCount)
set the maximum number of warnings for a given logger
int _maxWarning
maximum number of warnings for this logger.
static bool useShellColors
Use shell colour escape codes?
void debug(const std::string &message)
log a debug message
static ColorCodes & colorCodes()
A static map of shell color codes for the log levels.
static LogMap & existingLogs()
A static map of existing logs: we don't make more loggers than necessary.
int getLevel() const
Get the priority level of this logger.
friend std::ostream & operator<<(Log &log, int level)
Streaming output to a logger must have a Level/int as its first argument.
static bool showLoggerName
Show logger name?
static void setUseColors(bool useColors=true)
toggle whether to display colorful logging messages
std::string _name
This logger's name.
static std::mutex & displayLock()
Mutex to access screen (protected because external streaming operator uses it)
static void setLevel(const std::string &name, int level)
Set the log levels.
Log(const std::string &name)
Constructor by name.