summaryrefslogtreecommitdiff
path: root/sources/log.c
blob: ba0aa8652ca122ade225234454cd9dcaf969d15b (plain)
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
31
32
33
34
35
36
37
38
39
40
typedef enum log_kind
{
    LK_DEBUG,
    LK_INFO,
    LK_WARN,
    LK_ERROR,
    LK_FATAL,

    LK_ENUM_LEN

} log_kind;

static char* log_kind_names[LK_ENUM_LEN] =
{
    "DEBUG",
    "INFO",
    "WARN",
    "ERROR",
    "FATAL",
};

#define DBG   LK_DEBUG, __FILE__, __LINE__
#define INFO  LK_INFO,  __FILE__, __LINE__
#define WARN  LK_WARN,  __FILE__, __LINE__
#define ERR   LK_ERROR, __FILE__, __LINE__
#define FATAL LK_FATAL, __FILE__, __LINE__

void report(log_kind kind, const char* file, int line, const char* fmt, ...)
{
    va_list ap;

    /* TODO: log levels */

    printf("[%s] %s:%d - ", log_kind_names[kind], file, line);
    va_start(ap, fmt);
        vprintf(fmt, ap);
    va_end(ap);

    if(kind == LK_FATAL) abort();
}