Clear DeferredLogger's message container after logging.

This keeps from logging the same messages again. Also add clearMessages()
method, which is useful to clear the local container after gathering into
a global container (which leaves the local containers untouched).
This commit is contained in:
Atgeirr Flø Rasmussen
2019-04-30 12:24:31 +02:00
parent 9bbb0ef679
commit 32572ac2ab
3 changed files with 15 additions and 0 deletions

View File

@@ -86,6 +86,12 @@ namespace Opm
for (const auto& m : messages_) {
OpmLog::addTaggedMessage(m.flag, m.tag, m.text);
}
messages_.clear();
}
void DeferredLogger::clearMessages()
{
messages_.clear();
}
} // namespace Opm

View File

@@ -60,8 +60,13 @@ namespace Opm
void debug(const std::string& message);
void note(const std::string& message);
/// Log all messages to the OpmLog backends,
/// and clear the message container.
void logMessages();
/// Clear the message container without logging them.
void clearMessages();
private:
std::vector<Message> messages_;
friend Opm::DeferredLogger gatherDeferredLogger(const Opm::DeferredLogger& local_deferredlogger);

View File

@@ -63,6 +63,10 @@ inline void logAndCheckForExceptionsAndThrow(Opm::DeferredLogger& deferred_logge
if (terminal_output) {
global_deferredLogger.logMessages();
}
// Now that all messages have been logged, they are automatically
// cleared from the global logger, but we must also clear them
// from the local logger.
deferred_logger.clearMessages();
const auto& cc = Dune::MPIHelper::getCollectiveCommunication();
if (cc.max(exception_thrown) == 1) {
throw std::logic_error(message);