Пример #1
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;
}
Пример #2
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;
}