Belle II Software light-2406-ragdoll
LogConnectionFilter.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#include <framework/logging/LogConnectionFilter.h>
10
11using namespace Belle2;
12using namespace std;
13
15 m_logConnection(logConnection),
16 m_previousMessage(LogConfig::c_Default, "", "", "", "", 0),
17 m_repeatCounter(0)
18{
19}
20
21
23{
25}
26
27
29{
30 return (m_logConnection && m_logConnection->isConnected());
31}
32
33
35{
36
37 if (message == m_previousMessage) {
39 // return true anyway since we will print the repeat message later so we
40 // consider this successful
41 return true;
42 }
43
45 m_previousMessage = message;
46
47 return m_logConnection->sendMessage(message);
48}
49
50
52{
53 if (m_repeatCounter > 0) {
54 const std::string message{" ... message repeated " + std::to_string(m_repeatCounter) + " times"};
55 LogMessage repeatMessage(m_previousMessage.getLogLevel(), message, "", "", "", 0);
56 repeatMessage.setLogInfo(LogConfig::c_Message);
57 m_logConnection->sendMessage(repeatMessage);
58 }
60}
The LogConfig class.
Definition: LogConfig.h:22
@ c_Message
Log message text.
Definition: LogConfig.h:37
Abstract base class for the different types of log connections.
std::unique_ptr< LogConnectionBase > m_logConnection
The actual log connection.
void printRepetitions()
If there are repeated messages print the number of repetitions.
int m_repeatCounter
Counter for repeated messages.
virtual ~LogConnectionFilter()
The LogConnectionFilter destructor.
LogConnectionFilter(LogConnectionBase *logConnection)
The constructor.
LogMessage m_previousMessage
The previous log message.
bool isConnected() override
Returns true if the log connection could be established.
bool sendMessage(const LogMessage &message) override
Sends a log message.
The LogMessage class.
Definition: LogMessage.h:29
void setLogInfo(unsigned int logInfo)
Configure which information should be printed.
Definition: LogMessage.h:115
LogConfig::ELogLevel getLogLevel() const
Returns the log level of the message.
Definition: LogMessage.h:91
Abstract base class for different kinds of events.
Definition: ClusterUtils.h:24
STL namespace.