Logging commands

Defining logger objects

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

Generating log messages

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

Default parameters

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

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 <em>%log stream</em>,
- the <em>%log area</em>,
- the <em>%log level</em>.

These parameters are optional and may be specified <i>in arbitrary order</i> (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 \ref SENF_LOG_DEFAULT_STREAM, \ref SENF_LOG_DEFAULT_AREA
and \ref SENF_LOG_DEFAULT_LEVEL respectively. These macros set the default stream, area and/or
level <em>of the current scope</em>. 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 \e once within each scope.

The logging library defines the global defaults for stream, area and level to be \c
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 <em>compile time constants</em> (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.

Macro Definition Documentation

◆ SENF_LOG

#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 106 of file Log.hh.

◆ SENF_LOG_BLOCK

#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 133 of file Log.hh.

◆ SENF_LOG_BLOCK_TPL

#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 143 of file Log.hh.

◆ SENF_LOG_CLASS_AREA

#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 85 of file Definitions.hh.

◆ SENF_LOG_DEFAULT_AREA

#define SENF_LOG_DEFAULT_AREA (   area)

Set scope default log area.

Definition at line 39 of file Parameters.hh.

◆ SENF_LOG_DEFAULT_LEVEL

#define SENF_LOG_DEFAULT_LEVEL (   level)

Set scope default log level.

Definition at line 44 of file Parameters.hh.

◆ SENF_LOG_DEFAULT_STREAM

#define SENF_LOG_DEFAULT_STREAM (   stream)

Set scope default log stream.

Definition at line 34 of file Parameters.hh.

◆ SENF_LOG_DEFINE_ALIAS

#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 100 of file Definitions.hh.

◆ SENF_LOG_DEFINE_AREA

#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 71 of file Definitions.hh.

◆ SENF_LOG_DEFINE_NAMED_AREA

#define SENF_LOG_DEFINE_NAMED_AREA (   area,
  name 
)
Value:
SENF_LOG_DEFINE_AREA_I(area, \
std::string v_name() const { return name; } );
unspecified_keyword_type name

Definition at line 73 of file Definitions.hh.

◆ SENF_LOG_DEFINE_STREAM

#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 50 of file Definitions.hh.

◆ SENF_LOG_TPL

#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 116 of file Log.hh.

Function Documentation

◆ SENF_LOG_DEFINE_AREA()

senf::log::SENF_LOG_DEFINE_AREA ( DefaultArea  )

Default global log area.

◆ SENF_LOG_DEFINE_STREAM()

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

Default global log stream.