-
Notifications
You must be signed in to change notification settings - Fork 12
/
logmsg.h
52 lines (36 loc) · 1005 Bytes
/
logmsg.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
/*
Header: logmsg.h
Macros, functions and structures used for writing messages to a logfile.
(c)2013-2015, Levien van Zon (levien@zonnetjes.net)
*/
#include <stdio.h>
/* Logging macros */
#define LL_FATAL 1
#define LL_ERROR 2
#define LL_WARNING 3
#define LL_NORMAL 4
#define LL_VERBOSE 5
#define LL_DEBUG 6
typedef struct msglogger_struct {
char *logfile_name;
FILE *logfile;
int loglevel;
} messagelogger;
messagelogger logger;
static inline void init_msglogger() {
logger.logfile_name = NULL;
logger.logfile = stdout;
logger.loglevel = LL_NORMAL;
}
#define logmsg(level, format, args...) { \
if (level <= logger.loglevel && logger.logfile) { \
if (level == LL_WARNING) \
fprintf(logger.logfile, "WARNING: "); \
else if (level == LL_ERROR) \
fprintf(logger.logfile, "ERROR: "); \
else if (level == LL_FATAL) \
fprintf(logger.logfile, "FATAL ERROR: "); \
fprintf(logger.logfile, format, ##args); \
fflush(logger.logfile); \
} \
}