Skip to content

Commit 3d28557

Browse files
authored
Merge pull request #75 from sy-c/master
v2.3.0
2 parents 3b6e155 + 2a24368 commit 3d28557

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

doc/releaseNotes.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,6 @@ This file describes the main feature changes for each InfoLogger released versio
105105
- Added option for o2-infologger-log to collect logs from a named pipe (multiple clients possible). Pipe can be created and listened to continuously. e.g. `o2-infologger-log -f /tmp/log-pipe -c -l`.
106106
- API:
107107
- Added InfoLoggerContext light copy constructor, with fields overwrite. See example use in <../test/testInfoLogger.cxx>.
108+
109+
## v2.3.0 - 15/10/2021
110+
- Added possibility to use an AutoMuteToken in the c++ stream operator.

include/InfoLogger/InfoLogger.hxx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,10 @@ class InfoLogger
346346
/// Specialized << version to set message options
347347
InfoLogger& operator<<(const InfoLogger::InfoLoggerMessageOption options);
348348

349+
/// Specialized << version to set AutoMuteToken (by reference)
350+
/// NB: this overwrites InfoLoggerMessageOption / Severity if set.
351+
InfoLogger& operator<<(InfoLogger::AutoMuteToken * const token);
352+
349353
/// Log a message using the << operator, like for std::cout.
350354
/// All messages must be ended with the InfoLogger::StreamOps::endm tag.
351355
/// Severity/options can be set at any point in the stream (before endm). Severity set to Info by default.

src/InfoLogger.cxx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ class InfoLogger::Impl
185185
numberOfMessages = 0;
186186
currentStreamMessage.clear();
187187
currentStreamOptions = undefinedMessageOption;
188+
currentStreamToken = nullptr;
188189
client = nullptr;
189190

190191
floodReset();
@@ -395,6 +396,7 @@ class InfoLogger::Impl
395396
int numberOfMessages; //< number of messages received by this object
396397
std::string currentStreamMessage; //< temporary variable to store message when concatenating << operations, until "endm" is received
397398
InfoLoggerMessageOption currentStreamOptions; //< temporary variable to store message options when concatenating << operations, until "endm" is received
399+
InfoLogger::AutoMuteToken *currentStreamToken;//< temporary variable to store AutoMuteToken when concatenating << operations, until "endm" is received
398400

399401
InfoLoggerContext currentContext;
400402

@@ -900,9 +902,14 @@ InfoLogger& InfoLogger::operator<<(InfoLogger::StreamOps op)
900902

901903
// end of message: flush current buffer in a single message
902904
if (op == endm) {
903-
log(mPimpl->currentStreamOptions, "%s", mPimpl->currentStreamMessage.c_str());
905+
if (mPimpl->currentStreamToken != nullptr) {
906+
log(*mPimpl->currentStreamToken, "%s", mPimpl->currentStreamMessage.c_str());
907+
} else {
908+
log(mPimpl->currentStreamOptions, "%s", mPimpl->currentStreamMessage.c_str());
909+
}
904910
mPimpl->currentStreamMessage.clear();
905911
mPimpl->currentStreamOptions = undefinedMessageOption;
912+
mPimpl->currentStreamToken = nullptr;
906913
}
907914
return *this;
908915
}
@@ -919,6 +926,12 @@ InfoLogger& InfoLogger::operator<<(const InfoLogger::InfoLoggerMessageOption opt
919926
return *this;
920927
}
921928

929+
InfoLogger& InfoLogger::operator<<(InfoLogger::AutoMuteToken * const token)
930+
{
931+
mPimpl->currentStreamToken = token;
932+
return *this;
933+
}
934+
922935
InfoLogger::Severity InfoLogger::getSeverityFromString(const char* txt)
923936
{
924937
// permissive implementation

test/testInfoLogger.cxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ int main()
8888
theLog.log("Will now test auto-mute: limit = %d msg / %d s", limitN, limitT);
8989
// define a static variable token, and pass it to all relevant log() calls
9090
static InfoLogger::AutoMuteToken msgLimit(LogInfoDevel_(1234), limitN, limitT);
91+
theLog << &msgLimit << "This is message loop 0 (c++ style)" << InfoLogger::endm;
9192
// a couple of loops to show behavior
9293
for (int j=0; j<2; j++) {
9394
const int nmsg = 20 * limitN;

0 commit comments

Comments
 (0)