Esempio n. 1
0
void cLogger::print(SupportedTypes type_variant, int severity)
{
	std::string severity_str;
	//init severirity types
	if(LOG_SEV_INFO == severity)
	{
		severity_str = "INFO";
	}
	else
	{
		severity_str = (LOG_SEV_ERROR == severity) ? "ERROR" : "WARNING";
	}
	std::string message;
	cVariantVisitor variant_visitor(&message);
	boost::apply_visitor(variant_visitor, type_variant);
	std::string final_message = severity_str + " : " + GetCurrentDate() + " -- " + message + "\n";
	pushLogMessage(std::move(final_message));
}
Esempio n. 2
0
void
logData (int level, LogDataFormatter *formatLogData, const void *data) {
  const char *prefix = NULL;
  int push = 0;

  if (level & LOG_FLG_CATEGORY) {
    int category = level & LOG_MSK_CATEGORY;
    if (!logCategoryFlags[category]) return;
    const LogCategoryEntry *ctg = &logCategoryTable[category];

    prefix = ctg->prefix;
    level = categoryLogLevel;
  } else {
    push = level <= LOG_WARNING;
  }

  {
    int write = level <= systemLogLevel;
    int print = level <= stderrLogLevel;

    if (write || print || push) {
      int oldErrno = errno;

      char record[0X1000];
      STR_BEGIN(record, sizeof(record));
      if (prefix) STR_PRINTF("%s: ", prefix);
      STR_FORMAT(formatLogData, data);
      STR_END;

      if (write) {
        writeLogRecord(record);

#if defined(WINDOWS)
        if (windowsEventLog != INVALID_HANDLE_VALUE) {
          const char *strings[] = {record};

          ReportEvent(
            windowsEventLog, toWindowsEventType(level), 0, 0, NULL,
            ARRAY_COUNT(strings), 0, strings, NULL
          );
        }

#elif defined(__MSDOS__)

#elif defined(__ANDROID__)
        __android_log_write(
          toAndroidLogPriority(level), PACKAGE_TARNAME, record
        );

#elif defined(HAVE_SYSLOG_H)
        if (syslogOpened) syslog(level, "%s", record);
#endif /* write system log */
      }

      if (print) {
        FILE *stream = stderr;
        lockStream(stream);

        if (logPrefixStack) {
          const char *prefix = getLogEntryText(logPrefixStack);

          if (*prefix) {
            fputs(prefix, stream);
            fputs(": ", stream);
          }
        }

        fputs(record, stream);
        fputc('\n', stream);

        flushStream(stream);
        unlockStream(stream);
      }

      if (push) pushLogMessage(record);
      errno = oldErrno;
    }
  }
}