Esempio n. 1
0
static inline void wbLogEntry_delete(wbLogEntry_t elem) {
  if (elem != NULL) {
    if (wbLogEntry_getMessage(elem) != NULL) {
      wbFree(wbLogEntry_getMessage(elem));
    }
    wbDelete(elem);
  }
  return;
}
Esempio n. 2
0
static inline string wbLogEntry_toJSON(wbLogEntry_t elem) {
  if (elem == NULL) {
    return "";
  } else if (WB_USE_JSON11) {
    json11::Json json = wbLogEntry_toJSONObject(elem);
    return json.string_value();
  } else {
    stringstream ss;

    ss << "{\n";
    ss << wbString_quote("id") << ":"
       << wbString_quote(wbLogEntry_getId(elem)) << ",\n";
    ss << wbString_quote("session_id") << ":"
       << wbString_quote(wbLogEntry_getSessionId(elem)) << ",\n";
    ss << wbString_quote("mpi_rank") << ":"
       << wbString(wbLogEntry_getMPIRank(elem)) << ",\n";
    ss << wbString_quote("level") << ":"
       << wbString_quote(getLevelName(wbLogEntry_getLevel(elem))) << ",\n";
    ss << wbString_quote("message") << ":"
       << wbString_quote(wbLogEntry_getMessage(elem)) << ",\n";
    ss << wbString_quote("file") << ":"
       << wbString_quote(wbLogEntry_getFile(elem)) << ",\n";
    ss << wbString_quote("function") << ":"
       << wbString_quote(wbLogEntry_getFunction(elem)) << ",\n";
    ss << wbString_quote("line") << ":" << wbLogEntry_getLine(elem)
       << ",\n";
    ss << wbString_quote("time") << ":" << wbLogEntry_getTime(elem)
       << "\n";
    ss << "}";

    return ss.str();
  }
  return "";
}
Esempio n. 3
0
void wbLogger_append(wbLogLevel_t level, string msg, const char *file,
                     const char *fun, int line) {
  wbLogEntry_t elem;
  wbLogger_t logger;

  wb_init(NULL, NULL);

  logger = _logger;

  if (wbLogger_getLevel(logger) < level) {
    return;
  }

  elem = wbLogEntry_initialize(level, msg, file, fun, line);

#ifdef wbLogger_printOnLog
  if (wbLogger_printOnLog) {
    if (level <= wbLogger_getLevel(logger) && elem) {
      json11::Json json = json11::Json::object{
          {"type", "logger"},
          {"id", wbLogEntry_getId(elem)},
          {"session_id", wbLogEntry_getSessionId(elem)},
          {"data", wbLogEntry_toJSONObject(elem)}};
      std::cout << json.dump() << std::endl;
    }
  }
#endif /* wbLogger_printOnLog */

  if (wbLogger_getHead(logger) == NULL) {
    wbLogger_setHead(logger, elem);
  } else {
    wbLogEntry_t prev = wbLogger_getHead(logger);

    while (wbLogEntry_hasNext(prev)) {
      prev = wbLogEntry_getNext(prev);
    }
    wbLogEntry_setNext(prev, elem);
  }

#if 0
  if (level <= wbLogger_getLevel(logger) && elem) {
    const char *levelName = getLevelName(level);

    fprintf(stderr, "= LOG: %s: %s (In %s:%s on line %d). =\n", levelName,
            wbLogEntry_getMessage(elem), wbLogEntry_getFile(elem),
            wbLogEntry_getFunction(elem), wbLogEntry_getLine(elem));
  }
#endif

  wbLogger_incrementLength(logger);

  return;
}
Esempio n. 4
0
static inline json11::Json wbLogEntry_toJSONObject(wbLogEntry_t elem) {
  json11::Json json = json11::Json::object{
      {"id", wbLogEntry_getId(elem)},
      {"session_id", wbLogEntry_getSessionId(elem)},
      {"mpi_rank", wbLogEntry_getMPIRank(elem)},
      {"level", getLevelName(wbLogEntry_getLevel(elem))},
      {"file", wbLogEntry_getFile(elem)},
      {"function", wbLogEntry_getFunction(elem)},
      {"line", wbLogEntry_getLine(elem)},
      {"time", wbLogEntry_getTime(elem)},
      {"message", wbLogEntry_getMessage(elem)},
  };
  return json;
}
Esempio n. 5
0
static inline string wbLogEntry_toXML(wbLogEntry_t elem) {
  if (elem != NULL) {
    stringstream ss;

    ss << "<entry>\n";
    ss << "<type>"
       << "LoggerElement"
       << "</type>\n";
    ss << "<level>" << wbLogEntry_getLevel(elem) << "</level>\n";
    ss << "<message>" << wbLogEntry_getMessage(elem) << "</message>\n";
    ss << "<file>" << wbLogEntry_getFile(elem) << "</file>\n";
    ss << "<function>" << wbLogEntry_getFunction(elem) << "</function>\n";
    ss << "<line>" << wbLogEntry_getLine(elem) << "</line>\n";
    ss << "<time>" << wbLogEntry_getTime(elem) << "</time>\n";
    ss << "</entry>\n";

    return ss.str();
  }
  return "";
}
Esempio n. 6
0
static inline string wbLogEntry_toJSON(wbLogEntry_t elem) {
  if (elem != NULL) {
    stringstream ss;

    ss << "{\n";
    ss << wbString_quote("level") << ":"
       << wbString_quote(getLevelName(wbLogEntry_getLevel(elem))) << ",\n";
    ss << wbString_quote("message") << ":"
       << wbString_quote(wbLogEntry_getMessage(elem)) << ",\n";
    ss << wbString_quote("file") << ":"
       << wbString_quote(wbLogEntry_getFile(elem)) << ",\n";
    ss << wbString_quote("function") << ":"
       << wbString_quote(wbLogEntry_getFunction(elem)) << ",\n";
    ss << wbString_quote("line") << ":" << wbLogEntry_getLine(elem) << ",\n";
    ss << wbString_quote("time") << ":" << wbLogEntry_getTime(elem) << "\n";
    ss << "}";

    return ss.str();
  }
  return "";
}
Esempio n. 7
0
void wbLogger_append(wbLogLevel_t level, string msg, const char *file,
                     const char *fun, int line) {
  wbLogEntry_t elem;
  wbLogger_t logger;

  wb_init();

  logger = _logger;

  if (wbLogger_getLevel(logger) < level) {
    return;
  }

  elem = wbLogEntry_initialize(level, msg, file, fun, line);

  if (wbLogger_getHead(logger) == NULL) {
    wbLogger_setHead(logger, elem);
  } else {
    wbLogEntry_t prev = wbLogger_getHead(logger);

    while (wbLogEntry_hasNext(prev)) {
      prev = wbLogEntry_getNext(prev);
    }
    wbLogEntry_setNext(prev, elem);
  }

#if 0
  if (level <= wbLogger_getLevel(logger) && elem) {
    const char *levelName = getLevelName(level);

    fprintf(stderr, "= LOG: %s: %s (In %s:%s on line %d). =\n", levelName,
            wbLogEntry_getMessage(elem), wbLogEntry_getFile(elem),
            wbLogEntry_getFunction(elem), wbLogEntry_getLine(elem));
  }
#endif

  wbLogger_incrementLength(logger);

  return;
}