Belle II Software development
LogConnectionFilter Class Referencefinal

Implements a log connection that filters repeated messages. More...

#include <LogConnectionFilter.h>

Inheritance diagram for LogConnectionFilter:
LogConnectionBase

Public Member Functions

 LogConnectionFilter (LogConnectionBase *logConnection)
 The constructor.
 
virtual ~LogConnectionFilter ()
 The LogConnectionFilter destructor.
 
bool sendMessage (const LogMessage &message) override
 Sends a log message.
 
bool isConnected () override
 Returns true if the log connection could be established.
 
void finalizeOnAbort () override
 Finalize on Abort: make sure last repetition is printed if there is any and that connected connection is also finalized.
 

Private Member Functions

void printRepetitions ()
 If there are repeated messages print the number of repetitions.
 

Private Attributes

std::unique_ptr< LogConnectionBasem_logConnection
 The actual log connection.
 
LogMessage m_previousMessage
 The previous log message.
 
int m_repeatCounter
 Counter for repeated messages.
 

Detailed Description

Implements a log connection that filters repeated messages.

This connection can be used to prevent printing of the same message again and again. Messages are suppressed if they match with the one previously sent.

Definition at line 28 of file LogConnectionFilter.h.

Constructor & Destructor Documentation

◆ LogConnectionFilter()

LogConnectionFilter ( LogConnectionBase logConnection)
explicit

The constructor.

Parameters
logConnectionThe log connection that actually prints the messages.

Definition at line 14 of file LogConnectionFilter.cc.

14 :
15 m_logConnection(logConnection),
16 m_previousMessage(LogConfig::c_Default, "", "", "", "", 0),
18{
19}
@ c_Default
Default: use globally configured log level.
Definition: LogConfig.h:32
std::unique_ptr< LogConnectionBase > m_logConnection
The actual log connection.
int m_repeatCounter
Counter for repeated messages.
LogMessage m_previousMessage
The previous log message.

◆ ~LogConnectionFilter()

~LogConnectionFilter ( )
virtual

The LogConnectionFilter destructor.

Definition at line 22 of file LogConnectionFilter.cc.

23{
25}
void printRepetitions()
If there are repeated messages print the number of repetitions.

Member Function Documentation

◆ finalizeOnAbort()

void finalizeOnAbort ( )
inlineoverridevirtual

Finalize on Abort: make sure last repetition is printed if there is any and that connected connection is also finalized.

Reimplemented from LogConnectionBase.

Definition at line 62 of file LogConnectionFilter.h.

63 {
65 m_logConnection->finalizeOnAbort();
66 }

◆ isConnected()

bool isConnected ( )
overridevirtual

Returns true if the log connection could be established.

Returns
True if the log connection could be established.

Implements LogConnectionBase.

Definition at line 28 of file LogConnectionFilter.cc.

29{
30 return (m_logConnection && m_logConnection->isConnected());
31}

◆ printRepetitions()

void printRepetitions ( )
private

If there are repeated messages print the number of repetitions.


Definition at line 51 of file LogConnectionFilter.cc.

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}
@ c_Message
Log message text.
Definition: LogConfig.h:37
The LogMessage class.
Definition: LogMessage.h:29
LogConfig::ELogLevel getLogLevel() const
Returns the log level of the message.
Definition: LogMessage.h:91

◆ sendMessage()

bool sendMessage ( const LogMessage message)
overridevirtual

Sends a log message.

Parameters
messageThe log message object.
Returns
Returns true if the message could be send.

Implements LogConnectionBase.

Definition at line 34 of file LogConnectionFilter.cc.

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}

Member Data Documentation

◆ m_logConnection

std::unique_ptr<LogConnectionBase> m_logConnection
private

The actual log connection.

Definition at line 72 of file LogConnectionFilter.h.

◆ m_previousMessage

LogMessage m_previousMessage
private

The previous log message.

Definition at line 73 of file LogConnectionFilter.h.

◆ m_repeatCounter

int m_repeatCounter
private

Counter for repeated messages.

Definition at line 74 of file LogConnectionFilter.h.


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