class Rivet::Log

Rivet::Log

Logging system for controlled & formatted writing to stdout.

#include <Logging.hh>

Public Types

Name
enumLevel { TRACE = 0, DEBUG = 10, INFO = 20, WARN = 30, WARNING = 30, ERROR = 40, CRITICAL = 50, ALWAYS = 50}
Log priority levels.
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 Functions

Name
Log &getLog(const std::string & name)
LevelgetLevelFromName(const std::string & level)
Get a log level enum from a string.
std::stringgetLevelName(int level)
Get the std::string representation of a log level.
intgetLevel() const
Get the priority level of this logger.
Log &setLevel(int level)
Set the priority level of this logger.
std::stringgetName() const
Get the name of this logger.
Log &setName(const std::string & name)
Set the name of this logger.
boolisActive(int level) const
Will this log level produce output on this logger at the moment?
voidtrace(const std::string & message)
voiddebug(const std::string & message)
voidinfo(const std::string & message)
voidwarn(const std::string & message)
voiderror(const std::string & message)
voidsetLevel(const std::string & name, int level)
Set the log levels.
voidsetLevels(const LevelMap & logLevels)
voidsetShowTimestamp(bool showTime =true)
voidsetShowLevel(bool showLevel =true)
voidsetShowLoggerName(bool showName =true)
voidsetUseColors(bool useColors =true)

Protected Functions

Name
Log(const std::string & name)
Constructor 1.
Log(const std::string & name, int level)
Constructor 2.
std::stringgetColorCode(int level)
voidlog(int level, const std::string & message)
Write a message at a particular level.
std::stringformatMessage(int level, const std::string & message)
Turn a message string into the current log format.

Friends

Name
std::ostream &operator«(Log & log, int level)
The streaming operator can use Log’s internals.

Public Types Documentation

enum Level

EnumeratorValueDescription
TRACE0
DEBUG10
INFO20
WARN30
WARNING30
ERROR40
CRITICAL50
ALWAYS50

Log priority levels.

typedef LogMap

typedef std::map<std::string, Log> Rivet::Log::LogMap;

Typedef for a collection of named logs.

typedef LevelMap

typedef std::map<std::string, int> Rivet::Log::LevelMap;

Typedef for a collection of named log levels.

typedef ColorCodes

typedef std::map<int, std::string> Rivet::Log::ColorCodes;

Typedef for a collection of shell color codes, accessed by log level.

Public Functions Documentation

function getLog

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

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

function getLevelFromName

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

Get a log level enum from a string.

function getLevelName

static std::string getLevelName(
    int level
)

Get the std::string representation of a log level.

function getLevel

inline int getLevel() const

Get the priority level of this logger.

function setLevel

inline Log & setLevel(
    int level
)

Set the priority level of this logger.

function getName

inline std::string getName() const

Get the name of this logger.

function setName

inline Log & setName(
    const std::string & name
)

Set the name of this logger.

function isActive

inline bool isActive(
    int level
) const

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

function trace

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

function debug

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

function info

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

function warn

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

function error

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

function setLevel

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

Set the log levels.

function setLevels

static void setLevels(
    const LevelMap & logLevels
)

function setShowTimestamp

static inline void setShowTimestamp(
    bool showTime =true
)

function setShowLevel

static inline void setShowLevel(
    bool showLevel =true
)

function setShowLoggerName

static inline void setShowLoggerName(
    bool showName =true
)

function setUseColors

static inline void setUseColors(
    bool useColors =true
)

Protected Functions Documentation

function Log

Log(
    const std::string & name
)

Constructor 1.

function Log

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

Constructor 2.

function getColorCode

static std::string getColorCode(
    int level
)

function log

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

Write a message at a particular level.

function formatMessage

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

Turn a message string into the current log format.

Friends

friend operator«

friend std::ostream & operator<<(
    Log & log,

    int level
);

The streaming operator can use Log’s internals.


Updated on 2022-08-07 at 20:17:17 +0100