1 #ifndef RIVET_LOGGING_HH 2 #define RIVET_LOGGING_HH 4 #include "Rivet/Config/RivetCommon.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;
30 static LogMap existingLogs;
33 static LevelMap defaultLevels;
36 static ColorCodes colorCodes;
39 static std::string endColorCode;
42 static bool showTimestamp;
45 static bool showLogLevel;
48 static bool showLoggerName;
51 static bool useShellColors;
57 static void setLevel(
const std::string& name,
int level);
58 static void setLevels(
const LevelMap& logLevels);
60 static void setShowTimestamp(
bool showTime=
true) {
61 showTimestamp = showTime;
64 static void setShowLevel(
bool showLevel=
true) {
65 showLogLevel = showLevel;
68 static void setShowLoggerName(
bool showName=
true) {
69 showLoggerName = showName;
72 static void setUseColors(
bool useColors=
true) {
73 useShellColors = useColors;
83 Log(
const std::string& name);
86 Log(
const std::string& name,
int level);
97 static Log&
getLog(
const std::string& name);
129 return (level >= _level);
134 void trace(
const std::string& message) {
log(TRACE, message); }
136 void debug(
const std::string& message) {
log(DEBUG, message); }
138 void info(
const std::string& message) {
log(INFO, message); }
140 void warn(
const std::string& message) {
log(WARN, message); }
142 void error(
const std::string& message) {
log(ERROR, message); }
157 void log(
int level,
const std::string& message);
160 std::string
formatMessage(
int level,
const std::string& message);
179 #define MSG_LVL(lvl, x) \ 181 if (getLog().isActive(lvl)) { \ 182 getLog() << lvl << x << endl; \ 186 #define MSG_TRACE(x) MSG_LVL(Log::TRACE, x) 187 #define MSG_DEBUG(x) MSG_LVL(Log::DEBUG, x) 188 #define MSG_INFO(x) MSG_LVL(Log::INFO, x) 189 #define MSG_WARNING(x) MSG_LVL(Log::WARNING, x) 190 #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:140
Definition: ALICE_2010_I880049.cc:13
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:93
static std::string getColorCode(int level)
Definition: Logging.cc:113
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:186
bool isActive(int level) const
Will this log level produce output on this logger at the moment?
Definition: Logging.hh:128
Log & setLevel(int level)
Set the priority level of this logger.
Definition: Logging.hh:105
friend std::ostream & operator<<(Log &log, int level)
The streaming operator can use Log's internals.
Definition: Logging.cc:193
Log & setName(const std::string &name)
Set the name of this logger.
Definition: Logging.hh:122
int getLevel() const
Get the priority level of this logger.
Definition: Logging.hh:100
std::map< std::string, Log > LogMap
Typedef for a collection of named logs.
Definition: Logging.hh:18
std::string formatMessage(int level, const std::string &message)
Turn a message string into the current log format.
Definition: Logging.cc:150
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:117