-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.h
36 lines (28 loc) · 1.19 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
#include <stdio.h>
#include <errno.h>
#include <string.h>
#define LOG_INFO "<I>"
#define LOG_ERR "<E>"
#define log(fmt,...) fprintf(stderr, "[%s] " fmt "\n", __func__, ##__VA_ARGS__)
#define log_nop(...)
#ifdef NDEBUG
#define log_debug log
#else
#define log_debug log_nop
#endif
#define log_errno(go, fmt, ...) ({ \
char err[255]; \
strerror_r(errno, err, sizeof(err)-1); \
\
log_error(go, fmt ": %s" , ##__VA_ARGS__, err); \
})
#define log_error(go, fmt, ...) ({ \
log(LOG_ERR " " fmt, ##__VA_ARGS__); \
go; \
}) \
#define log_gai(go, rv, fmt, ...) ({ \
if(rv == EAI_SYSTEM) \
log_errno(go, "[gai] " fmt, ##__VA_ARGS__); \
else \
log(LOG_ERR fmt "%s\n", gai_strerror(rv), ##__VA_ARGS__); \
})