agile is hosted by Hepforge, IPPP Durham

Log Class Reference

#include <Logging.hh>

Collaboration diagram for Log:

List of all members.

Public Types

enum  Level {
  TRACE = 0, DEBUG = 10, INFO = 20, WARN = 30,
  WARNING = 30, ERROR = 40, CRITICAL = 50, ALWAYS = 50
}
 

Log priority levels.

More...
typedef std::map< const
std::string, Log * > 
LogMap
 Typedef for a collection of named logs.
typedef std::map< const
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.
LogsetLevel (int level)
 Set the priority level of this logger.
std::string getName () const
 Get the name of this logger.
LogsetName (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)
void always (const std::string &message)

Static Public Member Functions

static void setLevel (const std::string &name, int level)
 Set the log levels.
static void setLevels (LevelMap &logLevels)
static void setShowTimestamp (const bool showTime=true)
static void setShowLevel (const bool showLevel=true)
static void setShowLoggerName (const bool showName=true)
static void setUseColors (const bool useColors=true)
static LoggetLog (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 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)
 Copy constructor.

Private Attributes

std::string _name
 This logger's name.
int _level
 Threshold level for this logger.

Static Private Attributes

static LogMap existingLogs
 A static std::map of existing logs: we don't make more loggers than necessary.
static LevelMap defaultLevels
 A static std::map of default log levels.
static ColorCodes colorCodes
 A static std::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
 Show timestamp?
static bool showLogLevel
 Show log level?
static bool showLoggerName
 Show logger name?
static bool useShellColors
 Use shell colour escape codes?

Friends

std::ostream & operator<< (Log &log, int level)
 The streaming operator can use Log's internals.

Detailed Description

Definition at line 9 of file Logging.hh.


Member Typedef Documentation

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.

typedef std::map<const std::string, int> LevelMap

Typedef for a collection of named log levels.

Definition at line 21 of file Logging.hh.

typedef std::map<const std::string, Log*> LogMap

Typedef for a collection of named logs.

Definition at line 18 of file Logging.hh.


Member Enumeration Documentation

enum Level

Log priority levels.

Enumerator:
TRACE 
DEBUG 
INFO 
WARN 
WARNING 
ERROR 
CRITICAL 
ALWAYS 

Definition at line 13 of file Logging.hh.

00013                {
00014       TRACE = 0, DEBUG = 10, INFO = 20, WARN = 30, WARNING = 30, ERROR = 40, CRITICAL = 50, ALWAYS = 50
00015     };


Constructor & Destructor Documentation

Log ( const std::string &  name  )  [protected]

Constructor 1.

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

Constructor 2.


Member Function Documentation

void always ( const std::string &  message  )  [inline]

Definition at line 141 of file Logging.hh.

References Log::ALWAYS, and Log::log().

00141 { log(ALWAYS, message); }

void debug ( const std::string &  message  )  [inline]

Definition at line 133 of file Logging.hh.

References Log::DEBUG, and Log::log().

00133 { log(DEBUG, message); }

void error ( const std::string &  message  )  [inline]

Definition at line 139 of file Logging.hh.

References Log::ERROR, and Log::log().

00139 { log(ERROR, message); }

std::string formatMessage ( int  level,
const std::string &  message 
) [protected]

Turn a message string into the current log format.

static std::string getColorCode ( int  level  )  [static, protected]

Copy constructor.

Copy assignment operator

int getLevel (  )  const [inline]

Get the priority level of this logger.

Definition at line 97 of file Logging.hh.

References Log::_level.

00097                          {
00098       return _level;
00099     }

static Level getLevelFromName ( const std::string &  level  )  [static]

Get a log level enum from a string.

static std::string getLevelName ( int  level  )  [static]

Get the string representation of a log level.

static Log& getLog ( const std::string &  name  )  [static]

Get a logger with the given name. The level will be taken from the "requestedLevels" static std::map or will be INFO by default.

std::string getName (  )  const [inline]

Get the name of this logger.

Definition at line 114 of file Logging.hh.

References Log::_name.

00114                               {
00115       return _name;
00116     }

void info ( const std::string &  message  )  [inline]

Definition at line 135 of file Logging.hh.

References Log::INFO, and Log::log().

00135 { log(INFO, message); }

bool isActive ( int  level  )  const [inline]

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

Definition at line 125 of file Logging.hh.

References Log::_level.

00125                                    {
00126       return (level >= _level);
00127     }

void log ( int  level,
const std::string &  message 
) [protected]

Write a message at a particular level.

Referenced by Log::always(), Log::debug(), Log::error(), Log::info(), Log::trace(), and Log::warn().

Log& setLevel ( int  level  )  [inline]

Set the priority level of this logger.

Definition at line 102 of file Logging.hh.

References Log::_level.

00102                              {
00103       _level = level;
00104       return *this;
00105     }

static void setLevel ( const std::string &  name,
int  level 
) [static]

Set the log levels.

static void setLevels ( LevelMap logLevels  )  [static]
Log& setName ( const std::string &  name  )  [inline]

Set the name of this logger.

Definition at line 119 of file Logging.hh.

References Log::_name.

00119                                         {
00120       _name = name;
00121       return *this;
00122     }

static void setShowLevel ( const bool  showLevel = true  )  [inline, static]

Definition at line 60 of file Logging.hh.

References Log::showLogLevel.

00060                                                         {
00061       showLogLevel = showLevel;
00062     }

static void setShowLoggerName ( const bool  showName = true  )  [inline, static]

Definition at line 64 of file Logging.hh.

References Log::showLoggerName.

00064                                                             {
00065       showLoggerName = showName;
00066     }

static void setShowTimestamp ( const bool  showTime = true  )  [inline, static]

Definition at line 56 of file Logging.hh.

References Log::showTimestamp.

00056                                                            {
00057       showTimestamp = showTime;
00058     }

static void setUseColors ( const bool  useColors = true  )  [inline, static]

Definition at line 68 of file Logging.hh.

References Log::useShellColors.

00068                                                         {
00069       useShellColors = useColors;
00070     }

void trace ( const std::string &  message  )  [inline]

Definition at line 131 of file Logging.hh.

References Log::log(), and Log::TRACE.

00131 { log(TRACE, message); }

void warn ( const std::string &  message  )  [inline]

Definition at line 137 of file Logging.hh.

References Log::log(), and Log::WARN.

00137 { log(WARN, message); }


Friends And Related Function Documentation

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

The streaming operator can use Log's internals.


Member Data Documentation

int _level [private]

Threshold level for this logger.

Definition at line 149 of file Logging.hh.

Referenced by Log::getLevel(), Log::isActive(), and Log::setLevel().

std::string _name [private]

This logger's name.

Definition at line 146 of file Logging.hh.

Referenced by Log::getName(), and Log::setName().

std::ostream* const _nostream

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

Todo:
Hide this...

Definition at line 162 of file Logging.hh.

ColorCodes colorCodes [static, private]

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

Definition at line 34 of file Logging.hh.

LevelMap defaultLevels [static, private]

A static std::map of default log levels.

Definition at line 31 of file Logging.hh.

std::string endColorCode [static, private]

Shell color code for the end of the log levels.

Definition at line 37 of file Logging.hh.

LogMap existingLogs [static, private]

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

Definition at line 28 of file Logging.hh.

bool showLoggerName [static, private]

Show logger name?

Definition at line 46 of file Logging.hh.

Referenced by Log::setShowLoggerName().

bool showLogLevel [static, private]

Show log level?

Definition at line 43 of file Logging.hh.

Referenced by Log::setShowLevel().

bool showTimestamp [static, private]

Show timestamp?

Definition at line 40 of file Logging.hh.

Referenced by Log::setShowTimestamp().

bool useShellColors [static, private]

Use shell colour escape codes?

Definition at line 49 of file Logging.hh.

Referenced by Log::setUseColors().


The documentation for this class was generated from the following file:
Generated on Tue Mar 6 10:39:41 2012 for AGILe - A Generator Interface Library (+ executable) by  doxygen 1.6.3