Belle II Software  release-05-02-19
LogMessage Class Reference

The LogMessage class. More...

#include <LogMessage.h>

Collaboration diagram for LogMessage:

Classes

struct  TextHasher
 Helper struct to hash and compare messages only by log level and message content. More...
 

Public Member Functions

 LogMessage (LogConfig::ELogLevel logLevel, const std::string &message, const char *package, std::string function, std::string file, unsigned int line, int debugLevel=0)
 The LogMessage constructor. More...
 
 LogMessage (LogConfig::ELogLevel logLevel, LogVariableStream &&messageStream, const char *package, std::string function, std::string file, unsigned int line, int debugLevel=0)
 The LogMessage constructor taking a LogVariableStream which can contains name/value pairs. More...
 
 LogMessage (LogMessage &&)=default
 Provide move constructor.
 
 LogMessage (LogMessage const &lm)=default
 Provide copy-constructor.
 
bool operator== (const LogMessage &message) const
 Compares two messages. More...
 
bool operator!= (const LogMessage &message) const
 Check for inequality.
 
LogMessageoperator= (const LogMessage &lvs)=default
 Custom assignment-operator, thanks to stringsream's incompetence ...
 
LogConfig::ELogLevel getLogLevel () const
 Returns the log level of the message. More...
 
const std::string & getPackage () const
 Returns the package where the message was sent from. More...
 
const std::string getMessage () const
 Returns the message text. More...
 
void setModule (const std::string &module)
 Configure which information should be printed.
 
void setLogInfo (unsigned int logInfo)
 Configure which information should be printed.
 
std::ostream & print (std::ostream &out) const
 Generate output stream. More...
 
std::string toJSON (bool complete) const
 Return a json string for the log message. More...
 
const std::vector< LogVar > & getLogVariables () const
 Return a reference to the log variables associated with this message.
 

Private Attributes

LogConfig::ELogLevel m_logLevel
 The log level of the message.
 
LogVariableStream m_message
 The message stream which should be sent.
 
std::string m_module
 The module name where the message was sent from.
 
std::string m_package
 The package name where the message was sent from.
 
std::string m_function
 The function name where the message was sent from.
 
std::string m_file
 The file name where the message was sent from.
 
unsigned int m_line
 The line number in the source code where the message was sent from.
 
int m_debugLevel
 The debug level for messages with level=c_Debug.
 
unsigned int m_logInfo
 kind of information to show (ORed combination of LogConfig::ELogInfo flags).
 

Detailed Description

The LogMessage class.

This class encapsulates a logging message.

Definition at line 39 of file LogMessage.h.

Constructor & Destructor Documentation

◆ LogMessage() [1/2]

LogMessage ( LogConfig::ELogLevel  logLevel,
const std::string &  message,
const char *  package,
std::string  function,
std::string  file,
unsigned int  line,
int  debugLevel = 0 
)

The LogMessage constructor.

Parameters
logLevelThe log level of the message (e.g. debug, info, warning, error, fatal).
messageThe message string which should be send. This will be internally converted to a LogVariableStream with the text message and 0 variables.
packageThe package name where the message was sent from (can be NULL)
functionThe function name where the message was sent from.
fileThe file name where the message was sent from.
lineThe line number in the source code where the message was sent from.

Definition at line 24 of file LogMessage.cc.

25  :
26  m_logLevel(logLevel),
27  m_message(message),
28  m_module(""),
29  m_package(package ? package : ""),
30  m_function(std::move(function)),
31  m_file(std::move(file)),
32  m_line(line),
33  m_debugLevel(debugLevel),
34  m_logInfo(0)
35 {
36 }

◆ LogMessage() [2/2]

LogMessage ( LogConfig::ELogLevel  logLevel,
LogVariableStream &&  messageStream,
const char *  package,
std::string  function,
std::string  file,
unsigned int  line,
int  debugLevel = 0 
)

The LogMessage constructor taking a LogVariableStream which can contains name/value pairs.

Parameters
logLevelThe log level of the message (e.g. debug, info, warning, error, fatal).
messageStreamThe LogVariableStream which should be send.
packageThe package name where the message was sent from (can be NULL)
functionThe function name where the message was sent from.
fileThe file name where the message was sent from.
lineThe line number in the source code where the message was sent from.

Definition at line 38 of file LogMessage.cc.

Member Function Documentation

◆ getLogLevel()

LogConfig::ELogLevel getLogLevel ( ) const
inline

Returns the log level of the message.

Returns
Returns the log level of the message.

Definition at line 99 of file LogMessage.h.

◆ getMessage()

const std::string getMessage ( ) const
inline

Returns the message text.

Returns
Returns the message text;

Definition at line 113 of file LogMessage.h.

◆ getPackage()

const std::string& getPackage ( ) const
inline

Returns the package where the message was sent from.

Returns
Returns the package where the message was sent from.

Definition at line 106 of file LogMessage.h.

◆ operator==()

bool operator== ( const LogMessage message) const

Compares two messages.

Returns
true if the message contents (including module, .cc line etc.) are equal.

Definition at line 53 of file LogMessage.cc.

◆ print()

std::ostream & print ( std::ostream &  out) const

Generate output stream.

Parameters
outThe output stream.

Definition at line 108 of file LogMessage.cc.

◆ toJSON()

std::string toJSON ( bool  complete) const

Return a json string for the log message.

The returned string will be a json object containing the full log message on one line

Parameters
completeif true include all fields independent of the logInfo settings

Definition at line 64 of file LogMessage.cc.


The documentation for this class was generated from the following files:
Belle2::LogMessage::m_debugLevel
int m_debugLevel
The debug level for messages with level=c_Debug.
Definition: LogMessage.h:168
Belle2::LogMessage::m_message
LogVariableStream m_message
The message stream which should be sent.
Definition: LogMessage.h:162
Belle2::LogMessage::m_package
std::string m_package
The package name where the message was sent from.
Definition: LogMessage.h:164
Belle2::LogMessage::m_logInfo
unsigned int m_logInfo
kind of information to show (ORed combination of LogConfig::ELogInfo flags).
Definition: LogMessage.h:170
Belle2::LogMessage::m_function
std::string m_function
The function name where the message was sent from.
Definition: LogMessage.h:165
Belle2::LogMessage::m_logLevel
LogConfig::ELogLevel m_logLevel
The log level of the message.
Definition: LogMessage.h:161
Belle2::LogMessage::m_module
std::string m_module
The module name where the message was sent from.
Definition: LogMessage.h:163
Belle2::LogMessage::m_file
std::string m_file
The file name where the message was sent from.
Definition: LogMessage.h:166
Belle2::LogMessage::m_line
unsigned int m_line
The line number in the source code where the message was sent from.
Definition: LogMessage.h:167