Belle II Software  release-08-01-10
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.
 
void setCount (int count)
 Set the number of occurrences.
 
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).
 
int m_count
 Number of occurrences of the same message.
 

Detailed Description

The LogMessage class.

This class encapsulates a logging message.

Definition at line 29 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.
debugLevelThe debug level of the message if the logLevel is c_Debug

Definition at line 25 of file LogMessage.cc.

26  :
27  m_logLevel(logLevel),
28  m_message(message),
29  m_module(""),
30  m_package(package ? package : ""),
31  m_function(std::move(function)),
32  m_file(std::move(file)),
33  m_line(line),
34  m_debugLevel(debugLevel),
35  m_logInfo(0),
36  m_count(0)
37 {
38 }
int m_debugLevel
The debug level for messages with level=c_Debug.
Definition: LogMessage.h:165
unsigned int m_logInfo
kind of information to show (ORed combination of LogConfig::ELogInfo flags).
Definition: LogMessage.h:167
LogVariableStream m_message
The message stream which should be sent.
Definition: LogMessage.h:159
unsigned int m_line
The line number in the source code where the message was sent from.
Definition: LogMessage.h:164
std::string m_file
The file name where the message was sent from.
Definition: LogMessage.h:163
std::string m_module
The module name where the message was sent from.
Definition: LogMessage.h:160
std::string m_function
The function name where the message was sent from.
Definition: LogMessage.h:162
LogConfig::ELogLevel m_logLevel
The log level of the message.
Definition: LogMessage.h:158
std::string m_package
The package name where the message was sent from.
Definition: LogMessage.h:161
int m_count
Number of occurrences of the same message.
Definition: LogMessage.h:168

◆ 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.
debugLevelThe debug level of the message if the logLevel is c_Debug

Definition at line 40 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 91 of file LogMessage.h.

91 {return m_logLevel; }

◆ getMessage()

const std::string getMessage ( ) const
inline

Returns the message text.

Returns
Returns the message text;

Definition at line 105 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 98 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 57 of file LogMessage.cc.

◆ print()

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

Generate output stream.

Parameters
outThe output stream.

Definition at line 128 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 68 of file LogMessage.cc.


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