library/logger/logger.hh

Contains the logger class and macros, based on Kasper’s KLogger class.

Date
Created on: 18.11.2011
Author
Marco Haag marco.haag@kit.edu

Defines

LOGGER_UTILITY_MACROS_
va_num_args(...)
va_num_args_impl(_1, _2, _3, _4, _5, N, ...)
macro_dispatcher(func, ...)
macro_dispatcher_(func, nargs)
macro_dispatcher__(func, nargs)
COLOR_NORMAL
COLOR_BRIGHT
COLOR_FOREGROUND_RED
COLOR_FOREGROUND_GREEN
COLOR_FOREGROUND_YELLOW
COLOR_FOREGROUND_BLUE
COLOR_FOREGROUND_CYAN
COLOR_FOREGROUND_WHITE
COLOR_PREFIX
COLOR_SUFFIX
COLOR_SEPARATOR
__DEFAULT_LOGGER
__LOG_LOCATION
__LOG_LOG_4(I, L, M, O)
__LOG_LOG_3(I, L, M)
__LOG_LOG_2(L, M)
__LOG_LOG_1(M)
__LOG_TRACE_2(I, M)
__LOG_TRACE_1(M)
__LOG_DEBUG_2(I, M)
__LOG_DEBUG_1(M)
__LOG_INFO_2(I, M)
__LOG_INFO_1(M)
__LOG_PROG_2(I, M)
__LOG_PROG_1(M)
__LOG_WARN_2(I, M)
__LOG_WARN_1(M)
__LOG_ERROR_2(I, M)
__LOG_ERROR_1(M)
__LOG_FATAL_2(I, M)
__LOG_FATAL_1(M)
__LOG_ASSERT_3(I, C, M)
__LOG_ASSERT_2(C, M)
__LOG_LOG_ONCE_3(I, L, M)
__LOG_LOG_ONCE_2(L, M)
__LOG_LOG_ONCE_1(M)
__LOG_TRACE_ONCE_2(I, M)
__LOG_TRACE_ONCE_1(M)
__LOG_DEBUG_ONCE_2(I, M)
__LOG_DEBUG_ONCE_1(M)
__LOG_INFO_ONCE_2(I, M)
__LOG_INFO_ONCE_1(M)
__LOG_WARN_ONCE_2(I, M)
__LOG_WARN_ONCE_1(M)
__LOG_ERROR_ONCE_2(I, M)
__LOG_ERROR_ONCE_1(M)
__LOG_FATAL_ONCE_2(I, M)
__LOG_FATAL_ONCE_1(M)
LOGGER(I, K)
LOG(...)
LTRACE(...)
LDEBUG(...)
LINFO(...)
LPROG(...)
LWARN(...)
LERROR(...)
LFATAL(...)
LASSERT(...)
LOG_ONCE(...)
LTRACE_ONCE(...)
LDEBUG_ONCE(...)
LINFO_ONCE(...)
LPROG_ONCE(...)
LWARN_ONCE(...)
LERROR_ONCE(...)
LFATAL_ONCE(...)
namespace scarab

The standard scarab namespace.

class logger
#include <logger.hh>

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:

This is equivalent to:

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

Public Types

enum ELevel

Values:

eTrace = 0
eDebug = 1
eInfo = 2
eProg = 3
eWarn = 4
eError = 5
eFatal = 6

Public Functions

logger(const char *name = 0)

Standard constructor assigning a name to the logger instance.

Parameters
  • name: The logger name.

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.

~logger()
bool IsLevelEnabled(ELevel level) const

Check whether a certain log-level is enabled.

Return
Parameters
  • level: The log level

void SetLevel(ELevel level) const

Set a logger’s minimum logging level

Parameters
  • level: The log level

void SetGlobalLevel(ELevel level) const

Set all loggers’ minimum logging level

Parameters
  • level: The log level

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
  • level: The log level.
  • message: The message.
  • loc: Source code location (set automatically by the corresponding macro).

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

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

Parameters
  • message: The message.
  • loc: Source code location (set automatically by the corresponding macro).

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

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

Parameters
  • message: The message.
  • loc: Source code location (set automatically by the corresponding macro).

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

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

Parameters
  • message: The message.
  • loc: Source code location (set automatically by the corresponding macro).

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

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

Parameters
  • message: The message.
  • loc: Source code location (set automatically by the corresponding macro).

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

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

Parameters
  • message: The message.
  • loc: Source code location (set automatically by the corresponding macro).

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

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

Parameters
  • message: The message.
  • loc: Source code location (set automatically by the corresponding macro).

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

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

Parameters
  • message: The message.
  • loc: Source code location (set automatically by the corresponding macro).

Public Static Functions

static logger &GetRootLogger()
void SetColored(bool flag)

Set whether colored text will be used

Parameters
  • flag: Bool determining whether colored text will be used

void SetOutStream(std::ostream *stream)

Set the ostream pointer used for standard output messages

Parameters
  • stream: Stream object for standard output

void SetErrStream(std::ostream *stream)

Set the ostream pointer used for standard error messages

Parameters
  • stream: Stream object for standard errors

Private Members

Private *fPrivate
struct Location
#include <logger.hh>

A simple struct used by the Logger macros to pass information about the filename and line number. Not to be used directly by the user!

Public Functions

Location(const char *const fileName = "", const char *const functionName = "", int lineNumber = -1)

Public Members

int fLineNumber
std::string fFileName
std::string fFunctionName