Belle II Software  release-08-01-10
LogVariableStream Class Reference

Specialized implementation of an ostream-like class where the << operator can be used to insert values. More...

#include <LogVariableStream.h>

Collaboration diagram for LogVariableStream:

Public Types

typedef std::basic_ostream< std::stringstream::char_type, std::stringstream::traits_type > __basic_ostream_type
 basic_ofstream which is used with ostream's utility functions
 

Public Member Functions

 LogVariableStream ()=default
 Default constructor with empty text and no variables.
 
 LogVariableStream (LogVariableStream &&)=default
 Provide default move constructor.
 
 LogVariableStream (const LogVariableStream &other)
 Implement custom copy-constructor, because stringstream's one is deleted.
 
 LogVariableStream (std::string const &text, std::map< std::string, std::string > variables={})
 Constructor which sets an initial text for this stream. More...
 
LogVariableStreamoperator<< (__basic_ostream_type &(*__pf)(__basic_ostream_type &))
 operator override for ostream modifier functions like std::endl who are directly applied to the underlying string stream.
 
LogVariableStreamoperator<< (LogVar const &var)
 Operator override which stores the LogVar information instead of putting it directly in the sstream.
 
LogVariableStreamoperator<< (LogModRealm const &var)
 Operator override which sets a realm dependent log level.
 
template<class TText >
std::enable_if< not std::is_fundamental< TText >::value, LogVariableStream & >::type operator<< (TText const &text)
 Templated operator which will be used for all non-fundamental types. More...
 
template<class PODTYPE >
std::enable_if< std::is_fundamental< PODTYPE >::value, LogVariableStream & >::type operator<< (PODTYPE pod)
 Templated operator which will be used for POD types (especially integers) and uses by-value. More...
 
bool operator== (const LogVariableStream &lvs) const
 Custom comparison operator.
 
LogVariableStreamoperator= (const LogVariableStream &lvs)
 Custom assignment-operator, thanks to stringsream's non-copy policy.
 
std::string str (bool showVariables=true) const
 Return the content of the stream as string. More...
 
std::string getMessage () const
 Return the constant message part without the variables.
 
const std::vector< LogVar > & getVariables () const
 Return the list of all defined variables.
 
void adjustLogLevel (Belle2::LogConfig::ELogLevel &logLevel) const
 Adjust the log level in case of a realm dependent modification.
 

Private Attributes

std::stringstream m_stringStream
 All non-LogVar items are directly forwarded to this stringstream.
 
std::vector< LogVarm_variables
 List of LogVars which were accepted so far.
 
Belle2::LogConfig::ELogLevel m_logLevelOverride = Belle2::LogConfig::c_Default
 Adjusted log level.
 

Detailed Description

Specialized implementation of an ostream-like class where the << operator can be used to insert values.

In addition to the regular ostream usage, this class also accepts the LogVar class, which contains the name of a variable and its value. If string part and variable part of a log message are separated in that manner, it is much easier to filter and aggregate messages.

Here is an example on the usage: LogVariableStream lvs; lvs << "Inconsistent data size between COPPER and CDC FEE." << LogVar("data length", dataLength) << LogVar("nWord", nWord) << LogVar("Node ID", iNode) << LogVar("Finness ID", iFiness)); std::string lvsAsString = lvs.str();

Definition at line 127 of file LogVariableStream.h.

Constructor & Destructor Documentation

◆ LogVariableStream()

LogVariableStream ( std::string const &  text,
std::map< std::string, std::string >  variables = {} 
)
inlineexplicit

Constructor which sets an initial text for this stream.

Parameters
textInitial text.
variablesMap of variables' names and values.

Definition at line 154 of file LogVariableStream.h.

Member Function Documentation

◆ operator<<() [1/2]

std::enable_if<std::is_fundamental<PODTYPE>::value, LogVariableStream&>::type operator<< ( PODTYPE  pod)
inline

Templated operator which will be used for POD types (especially integers) and uses by-value.

For cases where constants are declared "static const int Name = 23;" in header files but the .cc file contains no definition. In these cases, by-ref cannot be used because no memory location exists to get the reference.

Definition at line 206 of file LogVariableStream.h.

◆ operator<<() [2/2]

std::enable_if<not std::is_fundamental<TText>::value, LogVariableStream&>::type operator<< ( TText const &  text)
inline

Templated operator which will be used for all non-fundamental types.

This types can be accepted via const& and need no copy.

Definition at line 194 of file LogVariableStream.h.

◆ str()

std::string str ( bool  showVariables = true) const
inline

Return the content of the stream as string.

First the stringstream part and then a list of the variables

Definition at line 235 of file LogVariableStream.h.


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