Belle II Software development
|
Specialized implementation of an ostream-like class where the << operator can be used to insert values. More...
#include <LogVariableStream.h>
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. | |
LogVariableStream & | operator<< (__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. | |
LogVariableStream & | operator<< (LogVar const &var) |
Operator override which stores the LogVar information instead of putting it directly in the sstream. | |
LogVariableStream & | operator<< (LogModRealm const &var) |
Operator override which sets a realm dependent log level. | |
template<class TText > | |
std::enable_if< notstd::is_fundamental< TText >::value, LogVariableStream & >::type | operator<< (TText const &text) |
Templated operator which will be used for all non-fundamental types. | |
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. | |
bool | operator== (const LogVariableStream &lvs) const |
Custom comparison operator. | |
LogVariableStream & | operator= (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. | |
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< LogVar > | m_variables |
List of LogVars which were accepted so far. | |
Belle2::LogConfig::ELogLevel | m_logLevelOverride = Belle2::LogConfig::c_Default |
Adjusted log level. | |
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.
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
Definition at line 131 of file LogVariableStream.h.
|
inline |
Implement custom copy-constructor, because stringstream's one is deleted.
Definition at line 144 of file LogVariableStream.h.
|
inlineexplicit |
Constructor which sets an initial text for this stream.
text | Initial text. |
variables | Map of variables' names and values. |
Definition at line 154 of file LogVariableStream.h.
|
inline |
Adjust the log level in case of a realm dependent modification.
Definition at line 265 of file LogVariableStream.h.
|
inline |
Return the constant message part without the variables.
Definition at line 253 of file LogVariableStream.h.
|
inline |
Return the list of all defined variables.
Definition at line 259 of file LogVariableStream.h.
|
inline |
operator override for ostream modifier functions like std::endl who are directly applied to the underlying string stream.
Definition at line 167 of file LogVariableStream.h.
LogVariableStream & operator<< | ( | LogModRealm const & | var | ) |
Operator override which sets a realm dependent log level.
Definition at line 12 of file LogVariableStream.cc.
|
inline |
Operator override which stores the LogVar information instead of putting it directly in the sstream.
Definition at line 178 of file LogVariableStream.h.
|
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.
|
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.
|
inline |
Custom assignment-operator, thanks to stringsream's non-copy policy.
Definition at line 223 of file LogVariableStream.h.
|
inline |
Custom comparison operator.
Definition at line 215 of file LogVariableStream.h.
|
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.
|
private |
Adjusted log level.
Definition at line 281 of file LogVariableStream.h.
|
private |
All non-LogVar items are directly forwarded to this stringstream.
Definition at line 275 of file LogVariableStream.h.
|
private |
List of LogVars which were accepted so far.
Definition at line 278 of file LogVariableStream.h.