Skip to content

Commit

Permalink
Merge pull request #75 from sy-c/master
Browse files Browse the repository at this point in the history
v2.3.0
  • Loading branch information
sy-c authored Oct 15, 2021
2 parents 3b6e155 + 2a24368 commit 3d28557
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
3 changes: 3 additions & 0 deletions doc/releaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,6 @@ This file describes the main feature changes for each InfoLogger released versio
- 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`.
- API:
- Added InfoLoggerContext light copy constructor, with fields overwrite. See example use in <../test/testInfoLogger.cxx>.

## v2.3.0 - 15/10/2021
- Added possibility to use an AutoMuteToken in the c++ stream operator.
4 changes: 4 additions & 0 deletions include/InfoLogger/InfoLogger.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,10 @@ class InfoLogger
/// Specialized << version to set message options
InfoLogger& operator<<(const InfoLogger::InfoLoggerMessageOption options);

/// Specialized << version to set AutoMuteToken (by reference)
/// NB: this overwrites InfoLoggerMessageOption / Severity if set.
InfoLogger& operator<<(InfoLogger::AutoMuteToken * const token);

/// Log a message using the << operator, like for std::cout.
/// All messages must be ended with the InfoLogger::StreamOps::endm tag.
/// Severity/options can be set at any point in the stream (before endm). Severity set to Info by default.
Expand Down
15 changes: 14 additions & 1 deletion src/InfoLogger.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ class InfoLogger::Impl
numberOfMessages = 0;
currentStreamMessage.clear();
currentStreamOptions = undefinedMessageOption;
currentStreamToken = nullptr;
client = nullptr;

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

InfoLoggerContext currentContext;

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

// end of message: flush current buffer in a single message
if (op == endm) {
log(mPimpl->currentStreamOptions, "%s", mPimpl->currentStreamMessage.c_str());
if (mPimpl->currentStreamToken != nullptr) {
log(*mPimpl->currentStreamToken, "%s", mPimpl->currentStreamMessage.c_str());
} else {
log(mPimpl->currentStreamOptions, "%s", mPimpl->currentStreamMessage.c_str());
}
mPimpl->currentStreamMessage.clear();
mPimpl->currentStreamOptions = undefinedMessageOption;
mPimpl->currentStreamToken = nullptr;
}
return *this;
}
Expand All @@ -919,6 +926,12 @@ InfoLogger& InfoLogger::operator<<(const InfoLogger::InfoLoggerMessageOption opt
return *this;
}

InfoLogger& InfoLogger::operator<<(InfoLogger::AutoMuteToken * const token)
{
mPimpl->currentStreamToken = token;
return *this;
}

InfoLogger::Severity InfoLogger::getSeverityFromString(const char* txt)
{
// permissive implementation
Expand Down
1 change: 1 addition & 0 deletions test/testInfoLogger.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ int main()
theLog.log("Will now test auto-mute: limit = %d msg / %d s", limitN, limitT);
// define a static variable token, and pass it to all relevant log() calls
static InfoLogger::AutoMuteToken msgLimit(LogInfoDevel_(1234), limitN, limitT);
theLog << &msgLimit << "This is message loop 0 (c++ style)" << InfoLogger::endm;
// a couple of loops to show behavior
for (int j=0; j<2; j++) {
const int nmsg = 20 * limitN;
Expand Down

0 comments on commit 3d28557

Please sign in to comment.