-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathlog.h
34 lines (27 loc) · 769 Bytes
/
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
#ifndef _LOG_H
#define _LOG_H
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <syslog.h>
#define LOG(pri, msg, ...) do { \
if (pri < LOG_DEBUG || LogDebug) { \
if (Interactive) { \
fprintf(stderr, "%d [%s:%d]: " msg "\n", (pri), __FILE__, __LINE__, ##__VA_ARGS__); \
fflush(stderr); \
} else { \
syslog(pri, "[%s:%d]: " msg, __FILE__, __LINE__, ##__VA_ARGS__); \
} \
} \
} while(0)
#define ERR(msg, ...) do { \
LOG(LOG_ERR, msg, ##__VA_ARGS__); \
LOG(LOG_ERR, "\nErrno: %d (%s)\n", errno, strerror(errno)); \
} while(0)
#define ERR_RET(code, msg...) do { \
ERR(msg); \
return code; \
} while(0)
extern int Interactive;
extern int LogDebug;
#endif /* _LOG_H */