#include <Logging.hh>
Definition at line 9 of file Logging.hh.
Public Types | |
enum | Level { TRACE = 0, DEBUG = 10, INFO = 20, WARN = 30, WARNING = 30, ERROR = 40 } |
Log priority levels. More... | |
typedef std::map< std::string, Log * > | LogMap |
Typedef for a collection of named logs. | |
typedef std::map< std::string, int > | LevelMap |
Typedef for a collection of named log levels. | |
typedef std::map< int, std::string > | ColorCodes |
Typedef for a collection of shell color codes, accessed by log level. | |
Public Member Functions | |
int | getLevel () const |
Get the priority level of this logger. | |
Log & | setLevel (int level) |
Set the priority level of this logger. | |
std::string | getName () const |
Get the name of this logger. | |
Log & | setName (const std::string &name) |
Set the name of this logger. | |
bool | isActive (int level) const |
Will this log level produce output on this logger at the moment? | |
Explicit log methods | |
void | trace (const std::string &message) |
void | debug (const std::string &message) |
void | info (const std::string &message) |
void | warn (const std::string &message) |
void | error (const std::string &message) |
Static Public Member Functions | |
static void | setLevel (const std::string &name, int level) |
Set the log levels. | |
static void | setLevels (const LevelMap &logLevels) |
static void | setShowTimestamp (bool showTime=true) |
static void | setShowLevel (bool showLevel=true) |
static void | setShowLoggerName (bool showName=true) |
static void | setUseColors (bool useColors=true) |
static Log & | getLog (const std::string &name) |
static Level | getLevelFromName (const std::string &level) |
Get a log level enum from a string. | |
static std::string | getLevelName (int level) |
Get the std::string representation of a log level. | |
Public Attributes | |
std::ostream *const | _nostream |
Protected Member Functions | |
void | log (int level, const std::string &message) |
Write a message at a particular level. | |
std::string | formatMessage (int level, const std::string &message) |
Turn a message string into the current log format. | |
Hidden constructors etc. | |
Log (const std::string &name) | |
Constructor 1. | |
Log (const std::string &name, int level) | |
Constructor 2. | |
Static Protected Member Functions | |
static std::string | getColorCode (int level) |
Private Attributes | |
std::string | _name |
This logger's name. | |
int | _level |
Threshold level for this logger. | |
Static Private Attributes | |
static LogMap | existingLogs |
A static map of existing logs: we don't make more loggers than necessary. | |
static LevelMap | defaultLevels |
A static map of default log levels. | |
static ColorCodes | colorCodes |
A static map of shell color codes for the log levels. | |
static std::string | endColorCode |
Shell color code for the end of the log levels. | |
static bool | showTimestamp = false |
Show timestamp? | |
static bool | showLogLevel = true |
Show log level? | |
static bool | showLoggerName = true |
Show logger name? | |
static bool | useShellColors = true |
Use shell colour escape codes? | |
Friends | |
std::ostream & | operator<< (Log &log, int level) |
The streaming operator can use Log's internals. |
typedef std::map<std::string, int> LevelMap |
typedef std::map<int, std::string> ColorCodes |
Typedef for a collection of shell color codes, accessed by log level.
Definition at line 24 of file Logging.hh.
enum Level |
Log | ( | const std::string & | name | ) | [protected] |
Constructor 1.
Log | ( | const std::string & | name, | |
int | level | |||
) | [protected] |
Constructor 2.
static void setLevel | ( | const std::string & | name, | |
int | level | |||
) | [static] |
Set the log levels.
void setLevels | ( | const LevelMap & | logLevels | ) | [static] |
Definition at line 47 of file Logging.cc.
References Rivet::_updateLevels(), Log::defaultLevels, and Log::existingLogs.
00047 { 00048 for (LevelMap::const_iterator lev = logLevels.begin(); lev != logLevels.end(); ++lev) { 00049 defaultLevels[lev->first] = lev->second; 00050 } 00051 _updateLevels(defaultLevels, existingLogs); 00052 }
static void setShowTimestamp | ( | bool | showTime = true |
) | [inline, static] |
Definition at line 56 of file Logging.hh.
References Log::showTimestamp.
00056 { 00057 showTimestamp = showTime; 00058 }
static void setShowLevel | ( | bool | showLevel = true |
) | [inline, static] |
Definition at line 60 of file Logging.hh.
References Log::showLogLevel.
00060 { 00061 showLogLevel = showLevel; 00062 }
static void setShowLoggerName | ( | bool | showName = true |
) | [inline, static] |
Definition at line 64 of file Logging.hh.
References Log::showLoggerName.
00064 { 00065 showLoggerName = showName; 00066 }
static void setUseColors | ( | bool | useColors = true |
) | [inline, static] |
Definition at line 68 of file Logging.hh.
References Log::useShellColors.
00068 { 00069 useShellColors = useColors; 00070 }
string getColorCode | ( | int | level | ) | [static, protected] |
Definition at line 108 of file Logging.cc.
References Log::colorCodes, Log::DEBUG, Log::endColorCode, Log::ERROR, Log::INFO, Log::TRACE, Log::useShellColors, and Log::WARN.
00108 { 00109 if (!Log::useShellColors) return ""; 00110 // If the codes haven't been initialized, do so now. 00111 if (Log::colorCodes.empty()) { 00112 // If stdout is a valid tty, try to use the appropriate codes. 00113 if (isatty(1)) { 00114 /// @todo Test for VT100 compliance? 00115 Log::colorCodes[TRACE] = "\033[0;37m"; 00116 Log::colorCodes[DEBUG] = "\033[0;36m"; 00117 Log::colorCodes[INFO] = "\033[0;32m"; 00118 Log::colorCodes[WARN] = "\033[0;33m"; 00119 Log::colorCodes[ERROR] = "\033[0;31m"; 00120 Log::endColorCode = "\033[0m"; 00121 } else { 00122 Log::colorCodes[TRACE] = ""; 00123 Log::colorCodes[DEBUG] = ""; 00124 Log::colorCodes[INFO] = ""; 00125 Log::colorCodes[WARN] = ""; 00126 Log::colorCodes[ERROR] = ""; 00127 } 00128 } 00129 // Return the appropriate code from the colour map. 00130 /// @todo Do the map::upper_limit thing to find nearest level... 00131 return colorCodes[level]; 00132 }
static 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.
Referenced by Rivet::_geNormAlignment(), AnalysisLoader::_loadAnalysisPlugins(), AnalysisLoader::_registerBuilder(), ProjectionHandler::create(), HistoHandler::create(), ProjectionHandler::getLog(), ProjectionApplier::getLog(), Projection::getLog(), HistoHandler::getLog(), AnalysisHandler::getLog(), Analysis::getLog(), Run::init(), AnalysisInfo::make(), Run::openFile(), Run::processEvent(), and Run::readEvent().
int getLevel | ( | ) | const [inline] |
Get the priority level of this logger.
Definition at line 95 of file Logging.hh.
References Log::_level.
00095 { 00096 return _level; 00097 }
Log& setLevel | ( | int | level | ) | [inline] |
Set the priority level of this logger.
Definition at line 100 of file Logging.hh.
References Log::_level.
00100 { 00101 _level = level; 00102 return *this; 00103 }
static Level getLevelFromName | ( | const std::string & | level | ) | [static] |
Get a log level enum from a string.
string getLevelName | ( | int | level | ) | [static] |
Get the std::string representation of a log level.
Definition at line 88 of file Logging.cc.
References Log::DEBUG, Log::ERROR, Log::INFO, Log::TRACE, and Log::WARN.
00088 { 00089 /// @todo Do the map::upper_limit thing to find nearest level... 00090 switch(level) { 00091 case TRACE: 00092 return "TRACE"; 00093 case DEBUG: 00094 return "DEBUG"; 00095 case INFO: 00096 return "INFO"; 00097 case WARN: 00098 return "WARN"; 00099 case ERROR: 00100 return "ERROR"; 00101 default: 00102 return ""; 00103 } 00104 //throw Error("Enum value was not a valid log level. How did that happen?"); 00105 }
std::string getName | ( | ) | const [inline] |
Get the name of this logger.
Definition at line 112 of file Logging.hh.
References Log::_name.
00112 { 00113 return _name; 00114 }
Log& setName | ( | const std::string & | name | ) | [inline] |
Set the name of this logger.
Definition at line 117 of file Logging.hh.
References Log::_name.
00117 { 00118 _name = name; 00119 return *this; 00120 }
bool isActive | ( | int | level | ) | const [inline] |
Will this log level produce output on this logger at the moment?
Definition at line 123 of file Logging.hh.
References Log::_level.
Referenced by Rivet::_geNormAlignment(), Rivet::operator<<(), VetoedFinalState::project(), UnstableFinalState::project(), and InitialQuarks::project().
00123 { 00124 return (level >= _level); 00125 }
void trace | ( | const std::string & | message | ) | [inline] |
void debug | ( | const std::string & | message | ) | [inline] |
void info | ( | const std::string & | message | ) | [inline] |
void warn | ( | const std::string & | message | ) | [inline] |
void error | ( | const std::string & | message | ) | [inline] |
void log | ( | int | level, | |
const std::string & | message | |||
) | [protected] |
Write a message at a particular level.
Referenced by Log::debug(), Log::error(), Log::info(), Log::trace(), and Log::warn().
std::string formatMessage | ( | int | level, | |
const std::string & | message | |||
) | [protected] |
std::ostream& operator<< | ( | Log & | log, | |
int | level | |||
) | [friend] |
The streaming operator can use Log's internals.
Log::LogMap existingLogs [static, private] |
A static map of existing logs: we don't make more loggers than necessary.
Definition at line 28 of file Logging.hh.
Referenced by Log::setLevels().
Log::LevelMap defaultLevels [static, private] |
A static map of default log levels.
Definition at line 31 of file Logging.hh.
Referenced by Log::setLevels().
Log::ColorCodes colorCodes [static, private] |
A static map of shell color codes for the log levels.
Definition at line 34 of file Logging.hh.
Referenced by Log::getColorCode().
string endColorCode [static, private] |
Shell color code for the end of the log levels.
Definition at line 37 of file Logging.hh.
Referenced by Log::getColorCode().
bool showTimestamp = false [static, private] |
bool showLogLevel = true [static, private] |
bool showLoggerName = true [static, private] |
bool useShellColors = true [static, private] |
Use shell colour escape codes?
Definition at line 49 of file Logging.hh.
Referenced by Log::getColorCode(), and Log::setUseColors().
std::string _name [private] |
This logger's name.
Definition at line 142 of file Logging.hh.
Referenced by Log::getName(), and Log::setName().
int _level [private] |
Threshold level for this logger.
Definition at line 145 of file Logging.hh.
Referenced by Log::getLevel(), Log::isActive(), and Log::setLevel().
std::ostream* const _nostream |
A null output stream, used for piping discarded output to nowhere.
Definition at line 158 of file Logging.hh.
Referenced by Rivet::operator<<().