File: log_impl.h

package info (click to toggle)
mimic 0.7.0%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 11,204 kB
  • sloc: ansic: 484,549; sh: 490; makefile: 268
file content (30 lines) | stat: -rw-r--r-- 765 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#ifndef MIMIC_COMMON_LOG_IMPL_H
#define MIMIC_COMMON_LOG_IMPL_H

#include <stdarg.h>
#include <stdio.h>

#include "defs.h"
#include "log.h"

const char* log_prefixes[][2] = {
  {BOLD RED, N_("Error")},  {BOLD YELLOW, N_(" Warn")}, {BOLD GREEN, N_(" Info")},
  {BOLD BLUE, N_("Debug")}, {BOLD GRAY, N_("Trace")},
};

int log_verbosity = 2;

void log_any(int level, const char* fmt, ...) {
  va_list ap;
  va_start(ap, fmt);
  if (log_verbosity >= level) {
    fprintf(stderr, "%s%s " RESET, log_prefixes[level][0], gettext(log_prefixes[level][1]));
    if (level >= LOG_TRACE) fprintf(stderr, GRAY);
    vfprintf(stderr, fmt, ap);
    if (level >= LOG_TRACE) fprintf(stderr, RESET);
    fprintf(stderr, "\n");
  }
  va_end(ap);
}

#endif  // MIMIC_COMMON_LOG_IMPL_H