 |
Belle II Software
release-05-01-25
|
11 #include <framework/utilities/testhelpers/Fixtures.h>
12 #include <framework/logging/LogConnectionBase.h>
13 #include <framework/logging/LogConnectionConsole.h>
15 #include <boost/algorithm/string.hpp>
16 #include <boost/range/adaptors.hpp>
23 std::vector<Belle2::LogMessage>& m_messages;
26 explicit LogInterceptor(std::vector<Belle2::LogMessage>& messages): m_messages(messages) {}
28 bool isConnected()
override {
return true; }
30 bool sendMessage(
Belle2::LogMessage const& message)
override {m_messages.push_back(message);
return false; }
51 int messages = std::count_if(
m_messages.begin(),
m_messages.end(), [level](
const LogMessage & m) {
52 return m.getLogLevel() == level;
55 <<
", found " << messages;
63 ASSERT_FALSE(
m_messages.empty()) <<
"No message available to check";
65 for (
const auto& var : msg.getLogVariables()) {
67 if (
auto it = variables.find(var.getName()); it != variables.end()) {
68 EXPECT_EQ(it->second, var.getValue());
71 EXPECT_FALSE(strict) <<
"extra variable: " << var.getName() << std::endl;
74 EXPECT_TRUE(variables.empty()) <<
"Some requested log variables were not present in the log message: "
75 << boost::algorithm::join(variables | boost::adaptors::map_keys,
", ");
87 ASSERT_FALSE(
m_messages.empty()) <<
"No message available to check";
89 EXPECT_EQ(msg.getLogLevel(), level);
90 EXPECT_EQ(msg.getMessage(), message);
void resetLogConnections()
Removes all log connections.
void resetLogging()
Reset logging system to defaults: empty all log messages and reset connections to the default.
static const char * logLevelToString(ELogLevel logLevelType)
Converts a log level type to a string.
void expectMessageVariables(std::map< std::string, std::string > &&variables, bool strict=false)
check if the last message emitted contains the given variables and their values.
void SetUp() override
Add a log message interceptor.
void TearDown() override
And try to reset logging system to default.
ELogLevel
Definition of the supported log levels.
Abstract base class for the different types of log connections.
std::vector< LogMessage > m_messages
list of log messages
Some utilities to help with writing unit tests.
@ c_Error
Error: for things that went wrong and have to be fixed.
void expectMessage(LogConfig::ELogLevel level=LogConfig::c_Error, int count=1, bool strict=false)
check if there is a certain number of log messages of a given level
static LogSystem & Instance()
Static method to get a reference to the LogSystem instance.
void addLogConnection(LogConnectionBase *logConnection)
Adds a log connection object which is used to the send the logging messages.
void expectErrorWithVariables(std::map< std::string, std::string > &&variables, bool strict=false)
Expect an error with variables: This is a shorthand to check that there is exactly one error message ...
void clearMessages()
clear the list of save log messages
void expectMessageContent(LogConfig::ELogLevel level, const std::string &message)
check the content of the last log message against the given values