-
Notifications
You must be signed in to change notification settings - Fork 1
/
log.h
111 lines (90 loc) · 2.99 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
//
// Created by thomas on 27/01/21.
//
#ifndef UBPF_TOOLS_LOG_H
#define UBPF_TOOLS_LOG_H
#include <sys/types.h>
#include <stdint.h>
#include <stdio.h>
#define L_DEBUG "\001" /* Debugging messages */
#define L_TRACE "\002" /* Protocol tracing */
#define L_INFO "\003" /* Informational messages */
#define L_REMOTE "\004" /* Remote protocol errors */
#define L_WARN "\005" /* Local warnings */
#define L_ERR "\006" /* Local errors */
#define L_AUTH "\007" /* Authorization failed etc. */
#define L_FATAL "\010" /* Fatal errors */
#define L_BUG "\011" /* BIRD bugs */
// mask bit to be ORed in add_entry_log function
#define MASK_DEBUG (1)
#define MASK_TRACE (1 << 1)
#define MASK_INFO (1 << 2)
#define MASK_REMOTE (1 << 3)
#define MASK_WARN (1 << 4)
#define MASK_ERR (1 << 5)
#define MASK_AUTH (1 << 6)
#define MASK_FATAL (1 << 7)
#define MASK_BUG (1 << 8)
#define MASK_ALL (~0)
#define LOG_BUFFER_SIZE 1024
#define TM_DATETIME_BUFFER_SIZE 32
#define STACK_BUFFER_INIT(buf, size) \
do { \
buf.start = alloca(size); \
buf.pos = buf.start; \
buf.end = buf.start + size; \
} while(0)
#define LOG_BUFFER_INIT(buf) \
STACK_BUFFER_INIT(buf, LOG_BUFFER_SIZE)
static inline FILE *
rf_open(const char *name, const char *mode) {
FILE *f = fopen(name, mode);
if (!f)
return NULL;
return f;
}
struct log_config {
uint mask; /* Classes to log */
void *fh; /* FILE to log to, NULL=syslog */
FILE *rf; /* Resource for log file */
const char *filename; /* Log filename */
const char *backup; /* Secondary filename (for log rotation) */
off_t pos; /* Position/size of current log */
off_t limit; /* Log size limit */
int terminal_flag;
struct log_config *prev, *next;
int dynamic_alloc;
};
typedef struct buffer {
char *start;
char *pos;
char *end;
} buffer;
/**
* Used to init the logger. Additionnal file on which log message
* will be sent and stored
* @param logs a list of log_config
* @param file_path file on which the logger will write messages
* @param mask which
*/
struct log_config *add_log_entry(struct log_config **logs, const char *file_path, int mask);
/**
* Init the log manager
* @param dbg 1 if the logger should also output log on stderr. 0 otherwise
* @param new_syslog_name the name used and prepended on message sent to syslog
* @param extra_log other file to which logs must be written. By default only
* syslog is enabled. If dbg parameter is set, the logger also
* sends message to stderr
*/
void log_init(int dbg, const char *new_syslog_name, struct log_config *extra_log);
/**
* Log a message
* @param msg
* @param ... format
*/
void msg_log(const char *msg, ...);
/**
* Close the logger
*/
void logs_close(void);
#endif //UBPF_TOOLS_LOG_H