This repository has been archived by the owner on Dec 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
log.h
56 lines (47 loc) · 1.91 KB
/
log.h
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// log.h
#include "features.h"
#include <stdio.h>
#include <stdlib.h>
enum log_level {
LOG_TRACE = 0,
LOG_DEBUG,
LOG_INFO,
LOG_WARN,
LOG_ERROR,
LOG_FATAL,
LOG_PANIC,
};
#define LOG_LEVEL_MIN (LOG_TRACE)
#define LOG_LEVEL_MAX_INC (LOG_PANIC + 1)
extern enum log_level log_logging_level;
// These functions automatically add a newline.
int log_printf (
const char *, const char *, unsigned long long, enum log_level, const char *, ...);
#define logf(lvl, fmt, ...) (log_printf(__FILE__, __func__, __LINE__, lvl, fmt, ##__VA_ARGS__))
#define tracef(fmt, ...) (log_printf(__FILE__, __func__, __LINE__, LOG_TRACE, fmt, ##__VA_ARGS__))
#define debugf(fmt, ...) (log_printf(__FILE__, __func__, __LINE__, LOG_DEBUG, fmt, ##__VA_ARGS__))
#define infof(fmt, ...) (log_printf(__FILE__, __func__, __LINE__, LOG_INFO, fmt, ##__VA_ARGS__))
#define warnf(fmt, ...) (log_printf(__FILE__, __func__, __LINE__, LOG_WARN, fmt, ##__VA_ARGS__))
#define errorf(fmt, ...) (log_printf(__FILE__, __func__, __LINE__, LOG_ERROR, fmt, ##__VA_ARGS__))
#define fatalf(fmt, ...) { \
log_printf(__FILE__, __func__, __LINE__, LOG_FATAL, fmt, ##__VA_ARGS__); \
exit(1); \
}
#define panicf(fmt, ...) { \
log_printf(__FILE__, __func__, __LINE__, LOG_PANIC, fmt, ##__VA_ARGS__); \
abort(); \
}
#define logs(lvl, s) (log_printf(__FILE__, __func__, __LINE__, lvl, "%s", s))
#define traces(s) (log_printf(__FILE__, __func__, __LINE__, LOG_TRACE, "%s", s))
#define debugs(s) (log_printf(__FILE__, __func__, __LINE__, LOG_DEBUG, "%s", s))
#define infos(s) (log_printf(__FILE__, __func__, __LINE__, LOG_INFO, "%s", s))
#define warns(s) (log_printf(__FILE__, __func__, __LINE__, LOG_WARN, "%s", s))
#define errors(s) (log_printf(__FILE__, __func__, __LINE__, LOG_ERROR, "%s", s))
#define fatals(s) { \
log_printf(__FILE__, __func__, __LINE__, LOG_FATAL, "%s", s); \
exit(1); \
}
#define panics(s) { \
log_printf(__FILE__, __func__, __LINE__, LOG_PANIC, "%s", s); \
abort(); \
}