1 #ifndef RIVET_LOGGING_HH 2 #define RIVET_LOGGING_HH 4 #include "Rivet/Rivet.hh" 14 TRACE = 0, DEBUG = 10, INFO = 20, WARN = 30, WARNING = 30, ERROR = 40, CRITICAL = 50, ALWAYS = 50
18 typedef std::map<std::string, Log*>
LogMap;
28 static LogMap existingLogs;
31 static LevelMap defaultLevels;
34 static ColorCodes colorCodes;
37 static std::string endColorCode;
40 static bool showTimestamp;
43 static bool showLogLevel;
46 static bool showLoggerName;
49 static bool useShellColors;
53 static void setLevel(
const std::string& name,
int level);
54 static void setLevels(
const LevelMap& logLevels);
56 static void setShowTimestamp(
bool showTime=
true) {
57 showTimestamp = showTime;
60 static void setShowLevel(
bool showLevel=
true) {
61 showLogLevel = showLevel;
64 static void setShowLoggerName(
bool showName=
true) {
65 showLoggerName = showName;
68 static void setUseColors(
bool useColors=
true) {
69 useShellColors = useColors;
78 Log(
const std::string& name);
81 Log(
const std::string& name,
int level);
91 static Log&
getLog(
const std::string& name);
124 return (level >= _level);
129 void trace(
const std::string& message) {
log(TRACE, message); }
131 void debug(
const std::string& message) {
log(DEBUG, message); }
133 void info(
const std::string& message) {
log(INFO, message); }
135 void warn(
const std::string& message) {
log(WARN, message); }
137 void error(
const std::string& message) {
log(ERROR, message); }
149 void log(
int level,
const std::string& message);
152 std::string
formatMessage(
int level,
const std::string& message);
158 std::ostream*
const _nostream;
173 #define MSG_LVL(lvl, x) \ 175 if (getLog().isActive(lvl)) { \ 176 getLog() << lvl << x << endl; \ 180 #define MSG_TRACE(x) MSG_LVL(Log::TRACE, x) 181 #define MSG_DEBUG(x) MSG_LVL(Log::DEBUG, x) 182 #define MSG_INFO(x) MSG_LVL(Log::INFO, x) 183 #define MSG_WARNING(x) MSG_LVL(Log::WARNING, x) 184 #define MSG_ERROR(x) MSG_LVL(Log::ERROR, x) static Level getLevelFromName(const std::string &level)
Get a log level enum from a string.
Definition: Logging.cc:136
Definition: MC_JetAnalysis.hh:9
std::map< int, std::string > ColorCodes
Typedef for a collection of shell color codes, accessed by log level.
Definition: Logging.hh:24
Log(const std::string &name)
Constructor 1.
Definition: Logging.cc:19
static std::string getLevelName(int level)
Get the std::string representation of a log level.
Definition: Logging.cc:89
static std::string getColorCode(int level)
Definition: Logging.cc:109
static Log & getLog(const std::string &name)
Definition: Logging.cc:55
void log(int level, const std::string &message)
Write a message at a particular level.
Definition: Logging.cc:182
bool isActive(int level) const
Will this log level produce output on this logger at the moment?
Definition: Logging.hh:123
Log & setLevel(int level)
Set the priority level of this logger.
Definition: Logging.hh:100
friend std::ostream & operator<<(Log &log, int level)
The streaming operator can use Log's internals.
Definition: Logging.cc:189
Log & setName(const std::string &name)
Set the name of this logger.
Definition: Logging.hh:117
int getLevel() const
Get the priority level of this logger.
Definition: Logging.hh:95
std::string formatMessage(int level, const std::string &message)
Turn a message string into the current log format.
Definition: Logging.cc:146
static void setLevel(const std::string &name, int level)
Set the log levels.
Definition: Logging.cc:40
Level
Log priority levels.
Definition: Logging.hh:13
std::map< std::string, int > LevelMap
Typedef for a collection of named log levels.
Definition: Logging.hh:21
std::string getName() const
Get the name of this logger.
Definition: Logging.hh:112
std::map< std::string, Log * > LogMap
Typedef for a collection of named logs.
Definition: Logging.hh:18