Esempio n. 1
0
static int _log_prepare(int level, struct __sourceloc where)
{
    if (level == LOG_LEVEL_SILENT)
        return 0;
    if (strbuf_is_empty(&logbuf))
        strbuf_init(&logbuf, _log_buf, sizeof _log_buf);
    open_logging(); // Put initial INFO message at start of log file
#ifndef ANDROID
    const char *levelstr = "UNKWN:";
    switch (level) {
    case LOG_LEVEL_FATAL:
        levelstr = "FATAL:";
        break;
    case LOG_LEVEL_ERROR:
        levelstr = "ERROR:";
        break;
    case LOG_LEVEL_INFO:
        levelstr = "INFO:";
        break;
    case LOG_LEVEL_WARN:
        levelstr = "WARN:";
        break;
    case LOG_LEVEL_DEBUG:
        levelstr = "DEBUG:";
        break;
    }
    strbuf_sprintf(&logbuf, "%-6.6s ", levelstr);
#endif
    if (show_pid())
        strbuf_sprintf(&logbuf, "[%5u] ", getpid());
    if (show_time()) {
        struct timeval tv;
        if (gettimeofday(&tv, NULL) == -1) {
            strbuf_puts(&logbuf, "NOTIME______ ");
        } else {
            struct tm tm;
            char buf[20];
            if (strftime(buf, sizeof buf, "%T", localtime_r(&tv.tv_sec, &tm)) == 0)
                strbuf_puts(&logbuf, "EMPTYTIME___ ");
            else
                strbuf_sprintf(&logbuf, "%s.%03u ", buf, tv.tv_usec / 1000);
        }
    }
    if (where.file) {
        strbuf_sprintf(&logbuf, "%s", _trimbuildpath(where.file));
        if (where.line)
            strbuf_sprintf(&logbuf, ":%u", where.line);
        if (where.function)
            strbuf_sprintf(&logbuf, ":%s()", where.function);
        strbuf_putc(&logbuf, ' ');
    } else if (where.function) {
        strbuf_sprintf(&logbuf, "%s() ", where.function);
    }
    strbuf_putc(&logbuf, ' ');
    return 1;
}
Esempio n. 2
0
static char *
var_get_display_flags(DCVariable *var)
{
    StrBuf *out;
    uint32_t c;
    uint32_t flags;

    flags = *(uint32_t *) var->value;
    out = strbuf_new();
    for (c = 0; c < display_flag_count; c++) {
	if (flags & display_flag_details[c].flag) {
	    if (!strbuf_is_empty(out))
		strbuf_append_char(out, ' ');
	    strbuf_append(out, display_flag_details[c].name);
	}
    }

    return strbuf_free_to_string(out);
}
Esempio n. 3
0
static void _log_prefix(_log_iterator *it, int level)
{
  if (it->config == &config_file) {
    if (strbuf_is_empty(&_log_file_strbuf))
      strbuf_init(&_log_file_strbuf, _log_file_buf, sizeof _log_file_buf);
    else if (strbuf_len(&_log_file_strbuf))
      strbuf_putc(&_log_file_strbuf, '\n');
    it->xpf = XPRINTF_STRBUF(&_log_file_strbuf);
    _log_prefix_level(it, level);
  }
#ifdef ANDROID
  else if (it->config == &config.log.android) {
    strbuf_init(&_android_strbuf, _log_android_buf, sizeof _log_android_buf);
    it->xpf = XPRINTF_STRBUF(&_android_strbuf);
  }
#endif // ANDROID
  else if (it->config == &config.log.console) {
    it->xpf = XPRINTF_STDIO(logfile_stderr);
    _log_prefix_level(it, level);
  }
  else
    abort();
  if (it->config->show_pid)
    xprintf(it->xpf, "[%5u] ", getpid());
  if (it->config->show_time) {
    if (it->tv.tv_sec == 0) {
      xputs("NOTIME______ ", it->xpf);
    } else {
      char buf[50];
      if (strftime(buf, sizeof buf, "%T", &it->tm) == 0)
	xputs("EMPTYTIME___ ", it->xpf);
      else
	xprintf(it->xpf, "%s.%03u ", buf, (unsigned int)it->tv.tv_usec / 1000);
    }
  }
}