9#include <framework/logging/LogMessage.h>
11#include <framework/utilities/Utils.h>
12#include <framework/gearbox/Unit.h>
13#include <framework/pcore/ProcHandler.h>
14#include <framework/datastore/StoreObjPtr.h>
15#include <framework/dataobjects/EventMetaData.h>
16#include <framework/core/ProcessStatistics.h>
18#include <boost/property_tree/json_parser.hpp>
26 std::string function, std::string file,
unsigned int line,
int debugLevel) :
30 m_package(package ? package :
""),
31 m_function(
std::move(function)),
32 m_file(
std::move(file)),
34 m_debugLevel(debugLevel),
41 std::string function, std::string file,
unsigned int line,
int debugLevel) :
43 m_message(
std::move(messageStream)),
45 m_package(package ? package :
""),
46 m_function(
std::move(function)),
47 m_file(
std::move(file)),
49 m_debugLevel(debugLevel),
60 (
m_line == message.m_line) &&
65 (
m_file == message.m_file));
70 using namespace boost::property_tree::json_parser;
71 std::stringstream buffer;
83 buffer <<
",\"variables\":{";
85 for (
const auto& v : vars) {
86 if (!first) buffer <<
",";
87 buffer <<
'"' << create_escapes(v.getName()) <<
"\":\"" << create_escapes(v.getValue()) <<
'"';
94 buffer << R
"(,"module":")" << create_escapes(m_module) << '"';
96 buffer << R
"(,"package":")" << create_escapes(m_package) << '"';
98 buffer << R
"(,"function":")" << create_escapes(m_function) << '"';
100 buffer << R
"(,"file":")" << create_escapes(m_file) << '"';
102 buffer <<
",\"line\":" <<
m_line;
104 buffer <<
",\"timestamp\":" << std::fixed << std::setprecision(3) << time;
108 buffer <<
",\"count\":" <<
m_count;
111 buffer <<
",\"experiment\":" << eventMetaData->getExperiment();
112 buffer <<
",\"run\":" << eventMetaData->getRun();
113 buffer <<
",\"subrun\":" << eventMetaData->getSubrun();
114 buffer <<
",\"event\":" << eventMetaData->getEvent();
117 if (processStatistics.
isValid()) {
118 const auto& stats = processStatistics->getGlobal();
120 buffer <<
",\"nevents\":" << int(stats.getCalls());
135 const auto flags = out.flags();
136 const int oldprecision = out.precision(3);
138 out.precision(oldprecision);
189 return logMessage.
print(out);
bool getInitializeActive() const
Are we currently initializing modules?
@ c_Persistent
Object is available during entire execution time.
static DataStore & Instance()
Instance of singleton Store.
ELogLevel
Definition of the supported log levels.
@ c_Debug
Debug: for code development.
@ c_Module
Module in which the message was emitted.
@ c_File
Source file in which the message was emitted.
@ c_Function
Function in which the message was emitted.
@ c_Line
Line in source file in which the message was emitted.
@ c_Level
Log level of the message.
@ c_Package
Package in which the message was emitted.
@ c_Message
Log message text.
@ c_NoVariables
If set don't output any variables that are part of the message.
@ c_Timestamp
Time at which the message was emitted.
static const char * logLevelToString(ELogLevel logLevelType)
Converts a log level type to a string.
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.
std::string toJSON(bool complete) const
Return a json string for the log message.
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).
LogVariableStream m_message
The message stream which should be sent.
unsigned int m_line
The line number in the source code where the message was sent from.
std::string m_file
The file name where the message was sent from.
bool operator==(const LogMessage &message) const
Compares two messages.
std::string m_module
The module name where the message was sent from.
std::ostream & print(std::ostream &out) const
Generate output stream.
std::string m_function
The function name where the message was sent from.
LogConfig::ELogLevel m_logLevel
The log level of the message.
std::string m_package
The package name where the message was sent from.
int m_count
Number of occurrences of the same message.
@ c_BeginRun
Counting time/calls in beginRun()
static int EvtProcID()
Return ID of the current process.
Type-safe access to single objects in the data store.
bool isValid() const
Check whether the object was created.
static const double s
[second]
Specialized implementation of an ostream-like class where the << operator can be used to insert value...
const std::vector< LogVar > & getVariables() const
Return the list of all defined variables.
std::string getMessage() const
Return the constant message part without the variables.
void adjustLogLevel(Belle2::LogConfig::ELogLevel &logLevel) const
Adjust the log level in case of a realm dependent modification.
std::string str(bool showVariables=true) const
Return the content of the stream as string.
std::ostream & operator<<(std::ostream &output, const IntervalOfValidity &iov)
double getClock()
Return current value of the real-time clock.
Abstract base class for different kinds of events.