Scarab  v3.9.2
Project 8 C++ Utility Library
Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
logger Class Reference

#include <logger.hh>

Classes

struct  Location
 
struct  Private
 

Public Types

enum  ELevel : unsigned {
  eTrace = 0, eDebug = 10, eInfo = 20, eProg = 25,
  eWarn = 30, eError = 40, eFatal = 50
}
 

Public Member Functions

 logger (const char *name=0)
 
 logger (const std::string &name)
 
virtual ~logger ()
 
bool IsLevelEnabled (ELevel level) const
 
ELevel GetLevel () const
 
void SetLevel (ELevel level) const
 
void UseGlobalLevel () const
 
void Log (ELevel level, const std::string &message, const Location &loc=Location())
 
void LogTrace (const std::string &message, const Location &loc=Location())
 
void LogDebug (const std::string &message, const Location &loc=Location())
 
void LogInfo (const std::string &message, const Location &loc=Location())
 
void LogProg (const std::string &message, const Location &loc=Location())
 
void LogWarn (const std::string &message, const Location &loc=Location())
 
void LogError (const std::string &message, const Location &loc=Location())
 
void LogFatal (const std::string &message, const Location &loc=Location())
 

Static Public Member Functions

static loggerGetRootLogger ()
 
static logger::ELevel GetGlobalLevel ()
 
static void SetGlobalLevel (ELevel level)
 
static void SetColored (bool flag)
 
static void SetOutStream (std::ostream *stream)
 
static void SetErrStream (std::ostream *stream)
 

Private Attributes

std::shared_ptr< PrivatefPrivate
 

Detailed Description

The scarab logger.

The usage and syntax is inspired by log4j. logger itself uses the log4cxx library if it was available on the system during compiling, otherwise it falls back to std::stream.

The logger output can be configured in a file specified with the environment variable LOGGER_CONFIGURATION (by default log4cxx.properties in the config directory).

In most cases the following macro can be used to instantiate a Logger in your code:

LOGGER(myLogger, "loggerName");

This is equivalent to:

static mantis::logger myLogger("loggerName");

For logging the following macros can be used. The source code location will then automatically included in the output:

LOG(myLogger, level, "message");
LTRACE(myLogger, "message");
LDEBUG(myLogger, "message");
LINFO(myLogger, "message");
LPROG(myLogger, "message");
LWARN(myLogger, "message");
LERROR(myLogger, "message");
FATAL(myLogger, "message");
ASSERT(myLogger, assertion, "message");
LOG_ONCE(myLogger, level, "message");
TRACE_ONCE(myLogger, "message");
DEBUG_ONCE(myLogger, "message");
INFO_ONCE(myLogger, "message");
PROG_ONCE(myLogger, "message");
WARN_ONCE(myLogger, "message");
ERROR_ONCE(myLogger, "message");
FATAL_ONCE(myLogger, "message");

Definition at line 114 of file logger.hh.

Member Enumeration Documentation

◆ ELevel

enum ELevel : unsigned
strong
Enumerator
eTrace 
eDebug 
eInfo 
eProg 
eWarn 
eError 
eFatal 

Definition at line 122 of file logger.hh.

Constructor & Destructor Documentation

◆ logger() [1/2]

logger ( const char *  name = 0)

Standard constructor assigning a name to the logger instance.

Parameters
nameThe logger name.

Definition at line 222 of file logger.cc.

◆ logger() [2/2]

logger ( const std::string &  name)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 247 of file logger.cc.

◆ ~logger()

~logger ( )
virtual

Definition at line 265 of file logger.cc.

Member Function Documentation

◆ GetGlobalLevel()

logger::ELevel GetGlobalLevel ( )
static

Get the global minimum logging level

Definition at line 297 of file logger.cc.

◆ GetLevel()

logger::ELevel GetLevel ( ) const

Get the logger's minimum logging level

Returns
The log level

Definition at line 279 of file logger.cc.

◆ GetRootLogger()

static logger& GetRootLogger ( )
inlinestatic

Definition at line 148 of file logger.hh.

◆ IsLevelEnabled()

bool IsLevelEnabled ( ELevel  level) const

Check whether a certain log-level is enabled.

Parameters
levelThe log level
Returns

Definition at line 274 of file logger.cc.

◆ Log()

void Log ( ELevel  level,
const std::string &  message,
const Location loc = Location() 
)

Log a message with the specified level. Use the macro LOG(logger, level, message).

Parameters
levelThe log level.
messageThe message.
locSource code location (set automatically by the corresponding macro).

Definition at line 338 of file logger.cc.

◆ LogDebug()

void LogDebug ( const std::string &  message,
const Location loc = Location() 
)
inline

Log a message at DEBUG level. Use the macro LDEBUG(logger, message).

Parameters
messageThe message.
locSource code location (set automatically by the corresponding macro).

Definition at line 242 of file logger.hh.

◆ LogError()

void LogError ( const std::string &  message,
const Location loc = Location() 
)
inline

Log a message at ERROR level. Use the macro LERROR(logger, message).

Parameters
messageThe message.
locSource code location (set automatically by the corresponding macro).

Definition at line 282 of file logger.hh.

◆ LogFatal()

void LogFatal ( const std::string &  message,
const Location loc = Location() 
)
inline

Log a message at FATAL level. Use the macro FATAL(logger, message).

Parameters
messageThe message.
locSource code location (set automatically by the corresponding macro).

Definition at line 292 of file logger.hh.

◆ LogInfo()

void LogInfo ( const std::string &  message,
const Location loc = Location() 
)
inline

Log a message at INFO level. Use the macro LINFO(logger, message).

Parameters
messageThe message.
locSource code location (set automatically by the corresponding macro).

Definition at line 252 of file logger.hh.

◆ LogProg()

void LogProg ( const std::string &  message,
const Location loc = Location() 
)
inline

Log a message at PROG level. Use the macro PROG(logger, message).

Parameters
messageThe message.
locSource code location (set automatically by the corresponding macro).

Definition at line 262 of file logger.hh.

◆ LogTrace()

void LogTrace ( const std::string &  message,
const Location loc = Location() 
)
inline

Log a message at TRACE level. Use the macro LTRACE(logger, message).

Parameters
messageThe message.
locSource code location (set automatically by the corresponding macro).

Definition at line 232 of file logger.hh.

◆ LogWarn()

void LogWarn ( const std::string &  message,
const Location loc = Location() 
)
inline

Log a message at WARN level. Use the macro LWARN(logger, message).

Parameters
messageThe message.
locSource code location (set automatically by the corresponding macro).

Definition at line 272 of file logger.hh.

◆ SetColored()

void SetColored ( bool  flag)
static

Set whether colored text will be used

Parameters
flagBool determining whether colored text will be used

Definition at line 316 of file logger.cc.

◆ SetErrStream()

void SetErrStream ( std::ostream *  stream)
static

Set the ostream pointer used for standard error messages

Parameters
streamStream object for standard errors

Definition at line 332 of file logger.cc.

◆ SetGlobalLevel()

void SetGlobalLevel ( ELevel  level)
static

Set all loggers' minimum logging level

Parameters
levelThe log level

Definition at line 303 of file logger.cc.

◆ SetLevel()

void SetLevel ( ELevel  level) const

Set a logger's minimum logging level

Parameters
levelThe log level

Definition at line 284 of file logger.cc.

◆ SetOutStream()

void SetOutStream ( std::ostream *  stream)
static

Set the ostream pointer used for standard output messages

Parameters
streamStream object for standard output

Definition at line 326 of file logger.cc.

◆ UseGlobalLevel()

void UseGlobalLevel ( ) const

Set a logger's minimum logging level to the global level

Definition at line 290 of file logger.cc.

Member Data Documentation

◆ fPrivate

std::shared_ptr<Private> fPrivate
private

Definition at line 298 of file logger.hh.


The documentation for this class was generated from the following files: