Merge pull request #1809 from atgeirr/log-messages-only-once

Clear DeferredLogger's message container after logging.
This commit is contained in:
Bård Skaflestad 2019-04-30 15:47:40 +02:00 committed by GitHub
commit 4d76ea5000
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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);