Hammer  1.0.0
Helicity Amplitude Module for Matrix Element Reweighting
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Hammer::Log Class Reference

Logging class. More...

#include <Logging.hh>

+ Collaboration diagram for Hammer::Log:

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 LoggetLog (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 LogMapexistingLogs ()
 A static map of existing logs: we don't make more loggers than necessary. More...
 
static LevelMapdefaultLevels ()
 A static map of default log levels. More...
 
static WarningCountMapdefaultMaxWarnings ()
 A static map for counting how many warnings have been issued for each logger. More...
 
static ColorCodescolorCodes ()
 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...
 
LogsetLevel (int level)
 Set the priority level of this logger. More...
 
LogsetWarnCount (int numCount)
 Set the maximum number of warnings of this logger. More...
 
std::string getName () const
 Get the name of this logger. More...
 
LogsetName (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...
 

Detailed Description

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.

Member Typedef Documentation

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.

Member Enumeration Documentation

Log priority levels.

Enumerator
TRACE 
DEBUG 
INFO 
WARN 
WARNING 
ERROR 
CRITICAL 
ALWAYS 

Definition at line 45 of file Logging.hh.

Constructor & Destructor Documentation

Hammer::Log::Log ( const std::string &  name)
protected

Constructor by name.

Parameters
[in]namelogger name

Definition at line 95 of file Logging.cc.

Hammer::Log::Log ( const std::string &  name,
int  level 
)
protected

Constructor by name and verbosity level.

Parameters
[in]namelogger name
[in]levelverbosity level

Definition at line 99 of file Logging.cc.

Hammer::Log::Log ( const std::string &  name,
int  level,
int  maxCount 
)
protected

Constructor by name, verbosity level and warning count.

Parameters
[in]namelogger name
[in]levelverbosity level
[in]maxCountupper limit on the number of warnings

Definition at line 102 of file Logging.cc.

Member Function Documentation

Log::ColorCodes & Hammer::Log::colorCodes ( )
staticprivate

A static map of shell color codes for the log levels.

Returns
the color codes

Definition at line 39 of file Logging.cc.

void Hammer::Log::debug ( const std::string &  message)
inline

log a debug message

Parameters
[in]messagethe message text

Definition at line 288 of file Logging.hh.

Log::LevelMap & Hammer::Log::defaultLevels ( )
staticprivate

A static map of default log levels.

Returns
the default levels

Definition at line 29 of file Logging.cc.

Log::WarningCountMap & Hammer::Log::defaultMaxWarnings ( )
staticprivate

A static map for counting how many warnings have been issued for each logger.

Returns
the warning counts

Definition at line 34 of file Logging.cc.

mutex & Hammer::Log::displayLock ( )
staticprotected

Mutex to access screen (protected because external streaming operator uses it)

Returns
the mutex

Definition at line 54 of file Logging.cc.

string & Hammer::Log::endColorCode ( )
staticprivate

Shell color code for the end of the log levels.

Returns
the string

Definition at line 44 of file Logging.cc.

void Hammer::Log::error ( const std::string &  message)
inline

log an error message

Parameters
[in]messagethe message text

Definition at line 306 of file Logging.hh.

Log::LogMap & Hammer::Log::existingLogs ( )
staticprivate

A static map of existing logs: we don't make more loggers than necessary.

Returns
the existing logs

Definition at line 24 of file Logging.cc.

string Hammer::Log::formatMessage ( int  level,
const std::string &  message 
)
protected

Turn a message string into the current log format.

Parameters
[in]levelthe log level
[in]messagethe log message
Returns
the formatted message

Definition at line 274 of file Logging.cc.

string Hammer::Log::getColorCode ( int  level)
protected

provide the escape string for the color associated to a give log level

Parameters
[in]levelthe log level
Returns
the escape string
Todo:
Test for VT100 compliance?
Todo:
Do the map::upper_limit thing to find nearest level...

Definition at line 216 of file Logging.cc.

int Hammer::Log::getLevel ( ) const
inline

Get the priority level of this logger.

Returns
the verbosity level

Definition at line 312 of file Logging.hh.

Log::Level Hammer::Log::getLevelFromName ( const std::string &  level)
staticprotected

Get a log level enum from a string.

Parameters
[in]levelthe level name
Returns
the level enum

Definition at line 249 of file Logging.cc.

string Hammer::Log::getLevelName ( int  level)
staticprotected

Get the std::string representation of a log level.

Parameters
[in]levelthe level enum
Returns
the level name
Todo:
Do the map::upper_limit thing to find nearest level...

Definition at line 190 of file Logging.cc.

Log & Hammer::Log::getLog ( const std::string &  name)
static

Get a logger with the given name.

The level will be taken from the "requestedLevels" static map or will be INFO by default.

Parameters
[in]namethe name of the logger
Returns
a reference to the logger

Definition at line 139 of file Logging.cc.

int Hammer::Log::getMaxWarning ( ) const
inlineprotected

Get the maximum number of warnings for this logger.

Returns
the warning cutoff

Definition at line 210 of file Logging.hh.

std::string Hammer::Log::getName ( ) const
inlineprotected

Get the name of this logger.

Returns
the logger name

Definition at line 244 of file Logging.hh.

void Hammer::Log::info ( const std::string &  message)
inline

log an information message

Parameters
[in]messagethe message text

Definition at line 294 of file Logging.hh.

bool Hammer::Log::isActive ( int  level) const
inline

Will this log level produce output on this logger at the moment?

Definition at line 276 of file Logging.hh.

mutex & Hammer::Log::lock ( )
staticprotected

Mutex to modify global elements (protected because external streaming operator uses it)

Returns
the mutex

Definition at line 49 of file Logging.cc.

void Hammer::Log::log ( int  level,
const std::string &  message 
)
protected

Write a message at a particular level.

Parameters
[in]levelthe log level
[in]messagethe log message

Definition at line 310 of file Logging.cc.

void Hammer::Log::resetWarningCounters ( )
static

reset the warning counters for all loggers

Definition at line 132 of file Logging.cc.

void Hammer::Log::setLevel ( const std::string &  name,
int  level 
)
static

Set the log levels.

Parameters
[in]namethe name of the logger
[in]levelthe verbosity level

Definition at line 105 of file Logging.cc.

Log& Hammer::Log::setLevel ( int  level)
inlineprotected

Set the priority level of this logger.

Parameters
[in]levelthe verbosity level
Returns
a reference to itself

Definition at line 217 of file Logging.hh.

void Hammer::Log::setLevels ( const LevelMap logLevels)
static

Set the log levels all at once.

Parameters
[in]logLevelsthe verbosity level map

Definition at line 113 of file Logging.cc.

Log& Hammer::Log::setName ( const std::string &  name)
inlineprotected

Set the name of this logger.

Parameters
[in]namethe logger name
Returns
a reference to itself

Definition at line 251 of file Logging.hh.

static void Hammer::Log::setShowLevel ( bool  showLevel = true)
inlinestatic

toggle whether to display the verbosity level in a logging message

Parameters
[in]showLevelthe flag value

Definition at line 141 of file Logging.hh.

static void Hammer::Log::setShowLoggerName ( bool  showName = true)
inlinestatic

toggle whether to display the logger name in a logging message

Parameters
[in]showNamethe flag value

Definition at line 148 of file Logging.hh.

static void Hammer::Log::setShowTimestamp ( bool  showTime = true)
inlinestatic

toggle whether to include the timestamp in a logging message

Parameters
[in]showTimethe flag value

Definition at line 134 of file Logging.hh.

static void Hammer::Log::setUseColors ( bool  useColors = true)
inlinestatic

toggle whether to display colorful logging messages

Parameters
[in]useColorsthe flag value

Definition at line 155 of file Logging.hh.

Log& Hammer::Log::setWarnCount ( int  numCount)
inlineprotected

Set the maximum number of warnings of this logger.

Parameters
[in]numCountthe number of warnings
Returns
a reference to itself

Definition at line 226 of file Logging.hh.

void Hammer::Log::setWarningMaxCount ( const std::string &  name,
int  maxCount 
)
static

set the maximum number of warnings for a given logger

Parameters
[in]namethe logger name
[in]maxCountthe maximum number of warnings

Definition at line 124 of file Logging.cc.

void Hammer::Log::trace ( const std::string &  message)
inline

log a trace message

Parameters
[in]messagethe message text

Definition at line 282 of file Logging.hh.

void Hammer::Log::updateCounters ( )
staticprotected

updates the max warning numbers of all the loggers

Definition at line 76 of file Logging.cc.

void Hammer::Log::updateLevels ( )
staticprotected

updates the verbosity levels of all the loggers

Definition at line 66 of file Logging.cc.

void Hammer::Log::warn ( const std::string &  message)
inline

log a warning message

Parameters
[in]messagethe message text

Definition at line 300 of file Logging.hh.

Friends And Related Function Documentation

std::ostream& operator<< ( Log log,
int  level 
)
friend

Streaming output to a logger must have a Level/int as its first argument.

Parameters
[in]logthe logger
[in]levelthe log level
Returns
the output stream

Definition at line 334 of file Logging.cc.

Member Data Documentation

int Hammer::Log::_level
private

Threshold level for this logger.

Definition at line 329 of file Logging.hh.

int Hammer::Log::_maxWarning
private

maximum number of warnings for this logger.

Definition at line 335 of file Logging.hh.

std::string Hammer::Log::_name
private

This logger's name.

Definition at line 338 of file Logging.hh.

std::unique_ptr<std::ostream> const Hammer::Log::_nostream
protected

A null output stream, used for piping discarded output to nowhere.

Definition at line 321 of file Logging.hh.

int Hammer::Log::_warnCounter
private

number of warnings issued by this logger.

Definition at line 332 of file Logging.hh.

bool Hammer::Log::showLoggerName = true
staticprivate

Show logger name?

Definition at line 95 of file Logging.hh.

bool Hammer::Log::showLogLevel = true
staticprivate

Show log level?

Definition at line 92 of file Logging.hh.

bool Hammer::Log::showTimestamp = false
staticprivate

Show timestamp?

Definition at line 89 of file Logging.hh.

bool Hammer::Log::useShellColors = true
staticprivate

Use shell colour escape codes?

Definition at line 98 of file Logging.hh.


The documentation for this class was generated from the following files: