Skip to content

Commit

Permalink
Merge pull request #2966 from JasonRuonanWang/log
Browse files Browse the repository at this point in the history
make adiosLog only print the same message once, and throw exceptions regardless printing or not
  • Loading branch information
JasonRuonanWang authored Dec 2, 2021
2 parents 3b22543 + 8b54b13 commit 8b55962
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions source/adios2/helper/adiosLog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <ctime>
#include <iostream>
#include <sstream>
#include <unordered_set>

namespace adios2
{
Expand All @@ -26,6 +27,8 @@ std::string errorColor = "\033[1;31m";
std::string exceptionColor = "\033[1;34m";
std::string defaultColor = "\033[0m";

std::unordered_set<std::string> messages;

void Log(const std::string &component, const std::string &source,
const std::string &activity, const std::string &message,
const LogMode mode)
Expand All @@ -47,18 +50,25 @@ void Log(const std::string &component, const std::string &source,
const int verbosity, const LogMode mode)
{

if (mode != LogMode::EXCEPTION)
// don't print if
// 1. logRank does not meet commRank, or
// 2. priority does not meet verbosity, or
// 3. the same messaage has been already printed
if ((logRank >= 0 && commRank >= 0 && logRank != commRank) ||
priority > verbosity || messages.find(message) != messages.end())
{
if (logRank >= 0 && commRank >= 0 && logRank != commRank)
if (mode == LogMode::EXCEPTION)
{
return;
throw(message);
}
if (priority > verbosity)
else
{
return;
}
}

messages.insert(message);

std::stringstream m;

auto timeNow =
Expand Down

0 comments on commit 8b55962

Please sign in to comment.