Logging commands


Detailed Description

The logging library provides several commands to create log messages. All these macro commands take a variable number of arguments. Since this is not supported in a usable way by the C++ preprocessor, the arguments are encoded into a Boost.Preprocessor like sequence:
SENF_LOG( (senf::log::Debug)(senf::log::NOTICE)(FroblizerArea)("The log message") );

The argument is comprised of a sequence of parameters and the log message itself. The parameters are

  • the log stream,
  • the log area,
  • the log level.

These parameters are optional and may be specified in arbitrary order (with the log message always being the last sequence element) and even multiple times in the parameter sequence. If some argument type occurs multiple times, the last occurrence wins. If any one of the parameters is not specified, it's current default value will be used.

This current default value is set using SENF_LOG_DEFAULT_STREAM, SENF_LOG_DEFAULT_AREA and SENF_LOG_DEFAULT_LEVEL respectively. These macros set the default stream, area and/or level of the current scope. They may be used with a class declaration to set defaults for all class members or within a function or member body to set the default for that member only. They may be used only once within each scope.

The logging library defines the global defaults for stream, area and level to be senf::log::Debug, senf::log::DefaultArea, and senf::log::NONE respectively.

The log level senf::log::NONE is special. If the log level is set to this value, the log level will be set from the stream provided default value.

All these parameters must be compile time constants (they are all types, so it's difficult for them to be something else).

Aliases

To further simplify logging commands, aliases may be defined within any scope. An alias is an arbitrary collection of log parameters:
SENF_LOG_DEFINE_ALIAS( VerboseDebug, (senf::log::Debug)(senf::log::VERBOSE) );
Within log statements, aliases may be used like normal parameters. They will be substituted for the parameter sequence they represent:
SENF_LOG( (VerboseDebug)("Debug message") )
// is equivalent to
SENF_LOG( (senf::log::Debug)(senf::log::VERBOSE)("Debug message") )
Aliases may be used together with other parameters, even with further aliases in any order.

Defining logger objects

  senf::log::SENF_LOG_DEFINE_STREAM (Debug, MESSAGE, MESSAGE, NOTICE)
  Default global log stream.
  senf::log::SENF_LOG_DEFINE_AREA (DefaultArea)
  Default global log area.
#define  SENF_LOG_DEFINE_STREAM(stream, defaultLevel_, runtimeLimit_, compileLimit_)
  Define log stream.
#define  SENF_LOG_DEFINE_AREA(area)
  Define log area.
#define  SENF_LOG_CLASS_AREA()
  Define new default log area for the class.
#define  SENF_LOG_DEFINE_ALIAS(alias, args)
  Define log parameter alias.

Generating log messages

#define  SENF_LOG(args)
  Write log message.
#define  SENF_LOG_TPL(args)
  Write log message (template context).
#define  SENF_LOG_BLOCK(args)
  Enable block based on logging parameters.
#define  SENF_LOG_BLOCK_TPL(args)
  Write log message (template context).

Default parameters

#define  SENF_LOG_DEFAULT_STREAM(stream)
  Set scope default log stream.
#define  SENF_LOG_DEFAULT_AREA(area)
  Set scope default log area.
#define  SENF_LOG_DEFAULT_LEVEL(level)
  Set scope default log level.

Define Documentation

#define
SENF_LOG ( args  )

Write log message.

This macro will write it's last argument to the log stream. The last argument must be an expression which will be placed after a streaming operator<< (like some-log-stream << last-macro-arg).

SENF_LOG((parameters...)("log message " << args << ...));

Definition at line 112 of file Log.hh.

#define
SENF_LOG_BLOCK ( args  )

Enable block based on logging parameters.

This macro is like SENF_LOG, however instead of writing a simple message, this macro allows to specify a complete block of code to be executed if the log message is enabled.

SENF_LOG_BLOCK((parameters...)({
   // arbitrary code using 'log' for logging
   log << "log message";
}));

Definition at line 139 of file Log.hh.

#define
SENF_LOG_BLOCK_TPL ( args  )

Write log message (template context).

This macro is used like SENF_LOG_BLOCK() if called from a template context

Definition at line 149 of file Log.hh.

#define
SENF_LOG_CLASS_AREA ()

Define new default log area for the class.

This command declares the containing class to be it's own default log area. It is such like a combination of SENF_LOG_DEFINE_AREA and SENF_LOG_DEFAULT_AREA with a twist.

Definition at line 90 of file Definitions.hh.

#define
SENF_LOG_DEFAULT_AREA ( area  )

Set scope default log area.

Definition at line 48 of file Parameters.hh.

#define
SENF_LOG_DEFAULT_LEVEL ( level  )

Set scope default log level.

Definition at line 53 of file Parameters.hh.

#define
SENF_LOG_DEFAULT_STREAM ( stream  )

Set scope default log stream.

Definition at line 43 of file Parameters.hh.

#define
SENF_LOG_DEFINE_ALIAS ( alias,
args  )

Define log parameter alias.

Defines a new parameter alias named alias as an alias for the parameters in args. The alias is defined as a symbol in the current scope.

Definition at line 105 of file Definitions.hh.

#define
SENF_LOG_DEFINE_AREA ( area  )

Define log area.

Defines a new log area named area. The area is defined as a symbol in the current scope.

Definition at line 80 of file Definitions.hh.

#define
SENF_LOG_DEFINE_STREAM ( stream,
defaultLevel_,
runtimeLimit_,
compileLimit_  )

Define log stream.

Defines a new log stream named stream. The stream is defined as a symbol in the current scope.

defaultLevel defines the default log level for messages posted to this stream. runtimeLimit defines the default log limit. Messages with a level below this will not be output. compileLimit defines the default log level limit at compile time: Messages posted with a level below compileLimit will be discarded at compile time.

Normally the compileLimit will be NOTICE. This will enable all messages except VERBOSE messages. These must then be enabled explicitly using the compile time Configuration macro.

Definition at line 59 of file Definitions.hh.

#define
SENF_LOG_TPL ( args  )

Write log message (template context).

This macro is used like SENF_LOG() if called from a template context

Definition at line 122 of file Log.hh.


Function Documentation

senf::log::
SENF_LOG_DEFINE_AREA ( DefaultArea  )

Default global log area.

senf::log::
SENF_LOG_DEFINE_STREAM ( Debug  ,
MESSAGE  ,
MESSAGE  ,
NOTICE  )

Default global log stream.