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;
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;
166 std::ostream&
operator<<(Log& log,
int level);
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)