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
165
166
167
168
|
/*
* Copyright (C) Igor Sysoev
* Copyright (C) NGINX, Inc.
*/
#ifndef _NXT_LOG_H_INCLUDED_
#define _NXT_LOG_H_INCLUDED_
#define NXT_LOG_ALERT 0
#define NXT_LOG_ERR 1
#define NXT_LOG_WARN 2
#define NXT_LOG_NOTICE 3
#define NXT_LOG_INFO 4
#define NXT_LOG_DEBUG 5
#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_alert(task, ...) \
do { \
nxt_log_t *_log = (task)->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_alert(_log, ...) \
do { \
nxt_log_t *_log_ = (_log); \
\
_log_->handler(NXT_LOG_ALERT, _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_assert(c) \
do { \
if (nxt_slow_path(!(c))) { \
nxt_thread_log_alert("%s:%d assertion failed: %s", \
__FILE__, __LINE__, #c); \
nxt_abort(); \
} \
} while (0)
#else
#define nxt_debug(...)
#define nxt_log_debug(...)
#define nxt_assert(c)
#endif
#if (NXT_DEBUG_ALLOC)
#define nxt_debug_alloc(...) \
nxt_thread_log_debug(__VA_ARGS__)
#else
#define nxt_debug_alloc(...)
#endif
#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_ */
|