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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
/*
* Copyright (C) Igor Sysoev
* Copyright (C) NGINX, Inc.
*/
#ifndef _NXT_LOG_H_INCLUDED_
#define _NXT_LOG_H_INCLUDED_
#define NXT_LOG_EMERG 0
#define NXT_LOG_ALERT 1
#define NXT_LOG_CRIT 2
#define NXT_LOG_ERR 3
#define NXT_LOG_WARN 4
#define NXT_LOG_NOTICE 5
#define NXT_LOG_INFO 6
#define NXT_LOG_DEBUG 7
#define NXT_MAX_ERROR_STR 2048
typedef void nxt_cdecl (*nxt_log_handler_t)(nxt_uint_t level, nxt_log_t *log,
const char *fmt, ...);
typedef u_char *(*nxt_log_ctx_handler_t)(void *ctx, u_char *pos, u_char *end);
struct nxt_log_s {
uint32_t level;
uint32_t ident;
nxt_log_handler_t handler;
nxt_log_ctx_handler_t ctx_handler;
void *ctx;
};
NXT_EXPORT void nxt_log_start(const char *name);
NXT_EXPORT nxt_log_t *nxt_log_set_ctx(nxt_log_t *log,
nxt_log_ctx_handler_t handler, void *ctx);
NXT_EXPORT void nxt_cdecl nxt_log_handler(nxt_uint_t level, nxt_log_t *log,
const char *fmt, ...);
#define \
nxt_log_level_enough(log, level) \
((log)->level >= (level))
#define \
nxt_log_emerg(_log, ...) \
do { \
nxt_log_t *_log_ = (_log); \
\
_log_->handler(NXT_LOG_EMERG, _log_, __VA_ARGS__); \
} while (0)
#define \
nxt_log_alert(_log, ...) \
do { \
nxt_log_t *_log_ = (_log); \
\
_log_->handler(NXT_LOG_ALERT, _log_, __VA_ARGS__); \
} while (0)
#define nxt_log(task, _level, ...) \
do { \
nxt_log_t *log = (task)->log; \
nxt_uint_t _level_ = (_level); \
\
if (nxt_slow_path(log->level >= _level_)) { \
log->handler(_level_, log, __VA_ARGS__); \
} \
} while (0)
#define nxt_trace(task, ...) \
do { \
nxt_log_t *log = (task)->log; \
\
if (nxt_slow_path(log->level >= NXT_LOG_NOTICE || nxt_trace)) { \
log->handler(NXT_LOG_NOTICE, log, __VA_ARGS__); \
} \
} while (0)
#define \
nxt_log_error(_level, _log, ...) \
do { \
nxt_log_t *_log_ = (_log); \
nxt_uint_t _level_ = (_level); \
\
if (nxt_slow_path(_log_->level >= _level_)) { \
_log_->handler(_level_, _log_, __VA_ARGS__); \
} \
} while (0)
#if (NXT_DEBUG)
#define nxt_debug(task, ...) \
do { \
nxt_log_t *log = (task)->log; \
\
if (nxt_slow_path(log->level == NXT_LOG_DEBUG || nxt_debug)) { \
log->handler(NXT_LOG_DEBUG, log, __VA_ARGS__); \
} \
} while (0)
#define \
nxt_log_debug(_log, ...) \
do { \
nxt_log_t *_log_ = (_log); \
\
if (nxt_slow_path(_log_->level == NXT_LOG_DEBUG || nxt_debug)) { \
_log_->handler(NXT_LOG_DEBUG, _log_, __VA_ARGS__); \
} \
} while (0)
#define nxt_debug_alloc(...)
#else
#define nxt_debug(...)
#define nxt_debug_alloc(...)
#define \
nxt_log_debug(...)
#endif
#define \
nxt_main_log_emerg(...) \
nxt_log_emerg(&nxt_main_log, __VA_ARGS__)
#define \
nxt_main_log_alert(...) \
nxt_log_alert(&nxt_main_log, __VA_ARGS__)
#define \
nxt_main_log_error(level, ...) \
nxt_log_error(level, &nxt_main_log, __VA_ARGS__)
#define \
nxt_main_log_debug(...) \
nxt_log_debug(&nxt_main_log, __VA_ARGS__)
NXT_EXPORT extern nxt_uint_t nxt_debug;
NXT_EXPORT extern nxt_uint_t nxt_trace;
NXT_EXPORT extern nxt_log_t nxt_main_log;
NXT_EXPORT extern nxt_str_t nxt_log_levels[];
#endif /* _NXT_LOG_H_INCLUDED_ */
|