-
Notifications
You must be signed in to change notification settings - Fork 33
/
log.h
58 lines (44 loc) · 1.39 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
57
58
/*
* moxi logging API
*/
#ifndef _LOG_H_
#define _LOG_H_
#include <errno.h>
#include <string.h>
/*
* define the log levels
*/
#define MOXI_LOG_CRIT 1
#define MOXI_LOG_ERR 5
#define MOXI_LOG_INFO 10
#define MOXI_LOG_DEBUG 15
#define ERRORLOG_STDERR 0x1
#define ERRORLOG_FILE 0x2
#define ERRORLOG_SYSLOG 0x4
struct moxi_log {
int fd; /* log fd */
int log_level; /* logging level. default 5 */
int log_mode; /* syslog, log file, stderr */
char *log_ident; /* syslog identifier */
char *log_file; /* if log file is specified */
int use_syslog; /* set if syslog is being used */
char *logbuf; /* scratch buffer */
int logbuf_used; /* length of scratch buffer */
time_t cur_ts; /* current timestamp */
time_t last_generated_debug_ts;
};
typedef struct moxi_log moxi_log;
int log_error_open(moxi_log *);
int log_error_close(moxi_log *);
int log_error_write(moxi_log *, const char *filename, unsigned int line, const char *fmt, ...);
int log_error_cycle(moxi_log *);
#ifndef MAIN_CHECK
extern moxi_log *ml;
#define moxi_log_write(...) log_error_write (ml, __FILE__, __LINE__, __VA_ARGS__)
#else
#define moxi_log_write(...) fprintf(stderr, __VA_ARGS__)
#endif
#undef perror
#define perror(str) log_error_write(ml, __FILE__, __LINE__, str, ": %s", strerror(errno));
#endif