|
@@ -1,698 +0,0 @@
|
1
|
|
-Index: nginx-1.4.7/src/core/ngx_cycle.c
|
2
|
|
-===================================================================
|
3
|
|
---- nginx-1.4.7.orig/src/core/ngx_cycle.c
|
4
|
|
-+++ nginx-1.4.7/src/core/ngx_cycle.c
|
5
|
|
-@@ -85,6 +85,12 @@ ngx_init_cycle(ngx_cycle_t *old_cycle)
|
6
|
|
- cycle->pool = pool;
|
7
|
|
- cycle->log = log;
|
8
|
|
- cycle->new_log.log_level = NGX_LOG_ERR;
|
9
|
|
-+#if (NGX_ENABLE_SYSLOG)
|
10
|
|
-+ cycle->new_log.facility = SYSLOG_FACILITY;
|
11
|
|
-+ cycle->new_log.facility = ERR_SYSLOG_PRIORITY;
|
12
|
|
-+ cycle->new_log.syslog_on = 0;
|
13
|
|
-+ cycle->new_log.syslog_set = 0;
|
14
|
|
-+#endif
|
15
|
|
- cycle->old_cycle = old_cycle;
|
16
|
|
-
|
17
|
|
- cycle->conf_prefix.len = old_cycle->conf_prefix.len;
|
18
|
|
-Index: nginx-1.4.7/src/core/ngx_log.c
|
19
|
|
-===================================================================
|
20
|
|
---- nginx-1.4.7.orig/src/core/ngx_log.c
|
21
|
|
-+++ nginx-1.4.7/src/core/ngx_log.c
|
22
|
|
-@@ -10,6 +10,15 @@
|
23
|
|
-
|
24
|
|
-
|
25
|
|
- static char *ngx_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
|
26
|
|
-+#if (NGX_ENABLE_SYSLOG)
|
27
|
|
-+static char *ngx_set_syslog(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
|
28
|
|
-+void log_exit(ngx_cycle_t *cycle);
|
29
|
|
-+
|
30
|
|
-+typedef struct{
|
31
|
|
-+ ngx_str_t name;
|
32
|
|
-+ ngx_int_t macro;
|
33
|
|
-+} ngx_string_to_macro_t;
|
34
|
|
-+#endif
|
35
|
|
-
|
36
|
|
-
|
37
|
|
- static ngx_command_t ngx_errlog_commands[] = {
|
38
|
|
-@@ -21,6 +30,15 @@ static ngx_command_t ngx_errlog_command
|
39
|
|
- 0,
|
40
|
|
- NULL},
|
41
|
|
-
|
42
|
|
-+#if (NGX_ENABLE_SYSLOG)
|
43
|
|
-+ {ngx_string("syslog"),
|
44
|
|
-+ NGX_MAIN_CONF|NGX_CONF_TAKE12,
|
45
|
|
-+ ngx_set_syslog,
|
46
|
|
-+ 0,
|
47
|
|
-+ 0,
|
48
|
|
-+ NULL},
|
49
|
|
-+#endif
|
50
|
|
-+
|
51
|
|
- ngx_null_command
|
52
|
|
- };
|
53
|
|
-
|
54
|
|
-@@ -43,7 +61,11 @@ ngx_module_t ngx_errlog_module = {
|
55
|
|
- NULL, /* init thread */
|
56
|
|
- NULL, /* exit thread */
|
57
|
|
- NULL, /* exit process */
|
58
|
|
-- NULL, /* exit master */
|
59
|
|
-+#if (NGX_ENABLE_SYSLOG)
|
60
|
|
-+ log_exit, /* exit master */
|
61
|
|
-+#else
|
62
|
|
-+ NULL,
|
63
|
|
-+#endif
|
64
|
|
- NGX_MODULE_V1_PADDING
|
65
|
|
- };
|
66
|
|
-
|
67
|
|
-@@ -52,6 +74,48 @@ static ngx_log_t ngx_log;
|
68
|
|
- static ngx_open_file_t ngx_log_file;
|
69
|
|
- ngx_uint_t ngx_use_stderr = 1;
|
70
|
|
-
|
71
|
|
-+#if (NGX_ENABLE_SYSLOG)
|
72
|
|
-+static ngx_string_to_macro_t ngx_syslog_facilities[] = {
|
73
|
|
-+ {ngx_string("auth"), LOG_AUTH},
|
74
|
|
-+#if !(NGX_SOLARIS)
|
75
|
|
-+ {ngx_string("authpriv"), LOG_AUTHPRIV},
|
76
|
|
-+#endif
|
77
|
|
-+ {ngx_string("cron"), LOG_CRON},
|
78
|
|
-+ {ngx_string("daemon"), LOG_DAEMON},
|
79
|
|
-+#if !(NGX_SOLARIS)
|
80
|
|
-+ {ngx_string("ftp"), LOG_FTP},
|
81
|
|
-+#endif
|
82
|
|
-+ {ngx_string("kern"), LOG_KERN},
|
83
|
|
-+ {ngx_string("local0"), LOG_LOCAL0},
|
84
|
|
-+ {ngx_string("local1"), LOG_LOCAL1},
|
85
|
|
-+ {ngx_string("local2"), LOG_LOCAL2},
|
86
|
|
-+ {ngx_string("local3"), LOG_LOCAL3},
|
87
|
|
-+ {ngx_string("local4"), LOG_LOCAL4},
|
88
|
|
-+ {ngx_string("local5"), LOG_LOCAL5},
|
89
|
|
-+ {ngx_string("local6"), LOG_LOCAL6},
|
90
|
|
-+ {ngx_string("local7"), LOG_LOCAL7},
|
91
|
|
-+ {ngx_string("lpr"), LOG_LPR},
|
92
|
|
-+ {ngx_string("mail"), LOG_MAIL},
|
93
|
|
-+ {ngx_string("news"), LOG_NEWS},
|
94
|
|
-+ {ngx_string("syslog"), LOG_SYSLOG},
|
95
|
|
-+ {ngx_string("user"), LOG_USER},
|
96
|
|
-+ {ngx_string("uucp"), LOG_UUCP},
|
97
|
|
-+ { ngx_null_string, 0}
|
98
|
|
-+};
|
99
|
|
-+
|
100
|
|
-+static ngx_string_to_macro_t ngx_syslog_priorities[] = {
|
101
|
|
-+ {ngx_string("emerg"), LOG_EMERG},
|
102
|
|
-+ {ngx_string("alert"), LOG_ALERT},
|
103
|
|
-+ {ngx_string("crit"), LOG_CRIT},
|
104
|
|
-+ {ngx_string("error"), LOG_ERR},
|
105
|
|
-+ {ngx_string("err"), LOG_ERR},
|
106
|
|
-+ {ngx_string("warn"), LOG_WARNING},
|
107
|
|
-+ {ngx_string("notice"),LOG_NOTICE},
|
108
|
|
-+ {ngx_string("info"), LOG_INFO},
|
109
|
|
-+ {ngx_string("debug"), LOG_DEBUG},
|
110
|
|
-+ { ngx_null_string, 0}
|
111
|
|
-+};
|
112
|
|
-+#endif
|
113
|
|
-
|
114
|
|
- static ngx_str_t err_levels[] = {
|
115
|
|
- ngx_null_string,
|
116
|
|
-@@ -89,11 +153,16 @@ ngx_log_error_core(ngx_uint_t level, ngx
|
117
|
|
- va_list args;
|
118
|
|
- #endif
|
119
|
|
- u_char *p, *last, *msg;
|
120
|
|
-+#if (NGX_ENABLE_SYSLOG)
|
121
|
|
-+ u_char *errstr_syslog;
|
122
|
|
-+#endif
|
123
|
|
- u_char errstr[NGX_MAX_ERROR_STR];
|
124
|
|
-
|
125
|
|
-+#if !(NGX_ENABLE_SYSLOG)
|
126
|
|
- if (log->file->fd == NGX_INVALID_FILE) {
|
127
|
|
- return;
|
128
|
|
- }
|
129
|
|
-+#endif
|
130
|
|
-
|
131
|
|
- last = errstr + NGX_MAX_ERROR_STR;
|
132
|
|
-
|
133
|
|
-@@ -102,6 +171,10 @@ ngx_log_error_core(ngx_uint_t level, ngx
|
134
|
|
-
|
135
|
|
- p = errstr + ngx_cached_err_log_time.len;
|
136
|
|
-
|
137
|
|
-+#if (NGX_ENABLE_SYSLOG)
|
138
|
|
-+ errstr_syslog = p;
|
139
|
|
-+#endif
|
140
|
|
-+
|
141
|
|
- p = ngx_slprintf(p, last, " [%V] ", &err_levels[level]);
|
142
|
|
-
|
143
|
|
- /* pid#tid */
|
144
|
|
-@@ -140,11 +213,27 @@ ngx_log_error_core(ngx_uint_t level, ngx
|
145
|
|
-
|
146
|
|
- ngx_linefeed(p);
|
147
|
|
-
|
148
|
|
-+#if (NGX_ENABLE_SYSLOG)
|
149
|
|
-+ if (log->file != NULL && log->file->name.len != 0) {
|
150
|
|
- (void) ngx_write_fd(log->file->fd, errstr, p - errstr);
|
151
|
|
-+ }
|
152
|
|
-+
|
153
|
|
-+ /* Don't send the debug level info to syslog */
|
154
|
|
-+ if (log->syslog_on && level < NGX_LOG_DEBUG) {
|
155
|
|
-+ /* write to syslog */
|
156
|
|
-+ syslog(log->priority, "%.*s", (int)(p - errstr_syslog), errstr_syslog);
|
157
|
|
-+ }
|
158
|
|
-+#else
|
159
|
|
-+ (void) ngx_write_fd(log->file->fd, errstr, p - errstr);
|
160
|
|
-+#endif
|
161
|
|
-
|
162
|
|
- if (!ngx_use_stderr
|
163
|
|
- || level > NGX_LOG_WARN
|
164
|
|
-+#if (NGX_ENABLE_SYSLOG)
|
165
|
|
-+ || (log->file != NULL && log->file->fd == ngx_stderr))
|
166
|
|
-+#else
|
167
|
|
- || log->file->fd == ngx_stderr)
|
168
|
|
-+#endif
|
169
|
|
- {
|
170
|
|
- return;
|
171
|
|
- }
|
172
|
|
-@@ -367,6 +456,50 @@ ngx_log_create(ngx_cycle_t *cycle, ngx_s
|
173
|
|
- }
|
174
|
|
-
|
175
|
|
-
|
176
|
|
-+#if (NGX_ENABLE_SYSLOG)
|
177
|
|
-+ngx_int_t
|
178
|
|
-+ngx_log_get_priority(ngx_conf_t *cf, ngx_str_t *priority)
|
179
|
|
-+{
|
180
|
|
-+ ngx_int_t p = 0;
|
181
|
|
-+ ngx_uint_t n, match = 0;
|
182
|
|
-+
|
183
|
|
-+ for (n = 0; ngx_syslog_priorities[n].name.len != 0; n++) {
|
184
|
|
-+ if (ngx_strncmp(priority->data, ngx_syslog_priorities[n].name.data,
|
185
|
|
-+ ngx_syslog_priorities[n].name.len) == 0) {
|
186
|
|
-+ p = ngx_syslog_priorities[n].macro;
|
187
|
|
-+ match = 1;
|
188
|
|
-+ }
|
189
|
|
-+ }
|
190
|
|
-+
|
191
|
|
-+ if (!match) {
|
192
|
|
-+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
193
|
|
-+ "invalid syslog priority \"%V\"", priority);
|
194
|
|
-+ return -1;
|
195
|
|
-+ }
|
196
|
|
-+
|
197
|
|
-+ return p;
|
198
|
|
-+}
|
199
|
|
-+
|
200
|
|
-+
|
201
|
|
-+char *
|
202
|
|
-+ngx_log_set_priority(ngx_conf_t *cf, ngx_str_t *priority, ngx_log_t *log)
|
203
|
|
-+{
|
204
|
|
-+ log->priority = ERR_SYSLOG_PRIORITY;
|
205
|
|
-+
|
206
|
|
-+ if (priority->len == 0) {
|
207
|
|
-+ return NGX_CONF_OK;
|
208
|
|
-+ }
|
209
|
|
-+
|
210
|
|
-+ log->priority = ngx_log_get_priority(cf, priority);
|
211
|
|
-+ if (log->priority == (-1)) {
|
212
|
|
-+ return NGX_CONF_ERROR;
|
213
|
|
-+ }
|
214
|
|
-+
|
215
|
|
-+ return NGX_CONF_OK;
|
216
|
|
-+}
|
217
|
|
-+#endif
|
218
|
|
-+
|
219
|
|
-+
|
220
|
|
- char *
|
221
|
|
- ngx_log_set_levels(ngx_conf_t *cf, ngx_log_t *log)
|
222
|
|
- {
|
223
|
|
-@@ -429,6 +562,13 @@ static char *
|
224
|
|
- ngx_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
225
|
|
- {
|
226
|
|
- ngx_str_t *value, name;
|
227
|
|
-+#if (NGX_ENABLE_SYSLOG)
|
228
|
|
-+ u_char *off = NULL;
|
229
|
|
-+ ngx_str_t priority;
|
230
|
|
-+
|
231
|
|
-+ ngx_str_null(&name);
|
232
|
|
-+ ngx_str_null(&priority);
|
233
|
|
-+#endif
|
234
|
|
-
|
235
|
|
- if (cf->cycle->new_log.file) {
|
236
|
|
- return "is duplicate";
|
237
|
|
-@@ -436,7 +576,44 @@ ngx_error_log(ngx_conf_t *cf, ngx_comman
|
238
|
|
-
|
239
|
|
- value = cf->args->elts;
|
240
|
|
-
|
241
|
|
-+#if (NGX_ENABLE_SYSLOG)
|
242
|
|
-+ if (ngx_strncmp(value[1].data, "syslog", sizeof("syslog") - 1) == 0) {
|
243
|
|
-+ if (!cf->cycle->new_log.syslog_set) {
|
244
|
|
-+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
245
|
|
-+ "You must set the syslog directive and enable it first.");
|
246
|
|
-+ return NGX_CONF_ERROR;
|
247
|
|
-+ }
|
248
|
|
-+
|
249
|
|
-+ cf->cycle->new_log.syslog_on = 1;
|
250
|
|
-+
|
251
|
|
-+ if (value[1].data[sizeof("syslog") - 1] == ':') {
|
252
|
|
-+ priority.len = value[1].len - sizeof("syslog");
|
253
|
|
-+ priority.data = value[1].data + sizeof("syslog");
|
254
|
|
-+
|
255
|
|
-+ off = (u_char *)ngx_strchr(priority.data, (int) '|');
|
256
|
|
-+ if (off != NULL) {
|
257
|
|
-+ priority.len = off - priority.data;
|
258
|
|
-+
|
259
|
|
-+ off++;
|
260
|
|
-+ name.len = value[1].data + value[1].len - off;
|
261
|
|
-+ name.data = off;
|
262
|
|
-+ }
|
263
|
|
-+ }
|
264
|
|
-+ else {
|
265
|
|
-+ if (value[1].len > sizeof("syslog")) {
|
266
|
|
-+ name.len = value[1].len - sizeof("syslog");
|
267
|
|
-+ name.data = value[1].data + sizeof("syslog");
|
268
|
|
-+ }
|
269
|
|
-+ }
|
270
|
|
-+
|
271
|
|
-+ if (ngx_log_set_priority(cf, &priority, &cf->cycle->new_log) == NGX_CONF_ERROR) {
|
272
|
|
-+ return NGX_CONF_ERROR;
|
273
|
|
-+ }
|
274
|
|
-+ }
|
275
|
|
-+ else if (ngx_strcmp(value[1].data, "stderr") == 0) {
|
276
|
|
-+#else
|
277
|
|
- if (ngx_strcmp(value[1].data, "stderr") == 0) {
|
278
|
|
-+#endif
|
279
|
|
- ngx_str_null(&name);
|
280
|
|
-
|
281
|
|
- } else {
|
282
|
|
-@@ -457,3 +634,63 @@ ngx_error_log(ngx_conf_t *cf, ngx_comman
|
283
|
|
-
|
284
|
|
- return ngx_log_set_levels(cf, &cf->cycle->new_log);
|
285
|
|
- }
|
286
|
|
-+
|
287
|
|
-+
|
288
|
|
-+#if (NGX_ENABLE_SYSLOG)
|
289
|
|
-+
|
290
|
|
-+#define SYSLOG_IDENT_NAME "nginx"
|
291
|
|
-+
|
292
|
|
-+static char *
|
293
|
|
-+ngx_set_syslog(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
294
|
|
-+{
|
295
|
|
-+ char *program;
|
296
|
|
-+ ngx_str_t *value;
|
297
|
|
-+ ngx_int_t facility, match = 0;
|
298
|
|
-+ ngx_uint_t n;
|
299
|
|
-+
|
300
|
|
-+ value = cf->args->elts;
|
301
|
|
-+
|
302
|
|
-+ if (cf->cycle->new_log.syslog_set) {
|
303
|
|
-+ return "is duplicate";
|
304
|
|
-+ }
|
305
|
|
-+
|
306
|
|
-+ cf->cycle->new_log.syslog_set = 1;
|
307
|
|
-+
|
308
|
|
-+ for (n = 0; ngx_syslog_facilities[n].name.len != 0; n++) {
|
309
|
|
-+ if (ngx_strncmp(value[1].data, ngx_syslog_facilities[n].name.data,
|
310
|
|
-+ ngx_syslog_facilities[n].name.len) == 0) {
|
311
|
|
-+ facility = ngx_syslog_facilities[n].macro;
|
312
|
|
-+ match = 1;
|
313
|
|
-+ break;
|
314
|
|
-+ }
|
315
|
|
-+ }
|
316
|
|
-+
|
317
|
|
-+ if (match) {
|
318
|
|
-+ cf->cycle->new_log.facility = facility;
|
319
|
|
-+ cf->cycle->new_log.priority = ERR_SYSLOG_PRIORITY;
|
320
|
|
-+ }
|
321
|
|
-+ else {
|
322
|
|
-+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
323
|
|
-+ "invalid syslog facility \"%V\"", &value[1]);
|
324
|
|
-+ return NGX_CONF_ERROR;
|
325
|
|
-+ }
|
326
|
|
-+
|
327
|
|
-+ program = SYSLOG_IDENT_NAME;
|
328
|
|
-+ if (cf->args->nelts > 2) {
|
329
|
|
-+ program = (char *) value[2].data;
|
330
|
|
-+ }
|
331
|
|
-+
|
332
|
|
-+ openlog(program, LOG_ODELAY, facility);
|
333
|
|
-+
|
334
|
|
-+ return NGX_CONF_OK;
|
335
|
|
-+}
|
336
|
|
-+
|
337
|
|
-+
|
338
|
|
-+void log_exit(ngx_cycle_t *cycle)
|
339
|
|
-+{
|
340
|
|
-+ if (cycle->new_log.syslog_set) {
|
341
|
|
-+ closelog();
|
342
|
|
-+ }
|
343
|
|
-+}
|
344
|
|
-+#endif
|
345
|
|
-+
|
346
|
|
-Index: nginx-1.4.7/src/core/ngx_log.h
|
347
|
|
-===================================================================
|
348
|
|
---- nginx-1.4.7.orig/src/core/ngx_log.h
|
349
|
|
-+++ nginx-1.4.7/src/core/ngx_log.h
|
350
|
|
-@@ -12,6 +12,13 @@
|
351
|
|
- #include <ngx_config.h>
|
352
|
|
- #include <ngx_core.h>
|
353
|
|
-
|
354
|
|
-+#if (NGX_ENABLE_SYSLOG)
|
355
|
|
-+#include <syslog.h>
|
356
|
|
-+
|
357
|
|
-+#define SYSLOG_FACILITY LOG_LOCAL5
|
358
|
|
-+#define ERR_SYSLOG_PRIORITY LOG_ERR
|
359
|
|
-+#endif
|
360
|
|
-+
|
361
|
|
-
|
362
|
|
- #define NGX_LOG_STDERR 0
|
363
|
|
- #define NGX_LOG_EMERG 1
|
364
|
|
-@@ -61,6 +68,13 @@ struct ngx_log_s {
|
365
|
|
- */
|
366
|
|
-
|
367
|
|
- char *action;
|
368
|
|
-+
|
369
|
|
-+#if (NGX_ENABLE_SYSLOG)
|
370
|
|
-+ ngx_int_t priority;
|
371
|
|
-+ ngx_int_t facility;
|
372
|
|
-+ unsigned syslog_on:1; /* unsigned :1 syslog_on */
|
373
|
|
-+ unsigned syslog_set:1; /*unsigned :1 syslog_set */
|
374
|
|
-+#endif
|
375
|
|
- };
|
376
|
|
-
|
377
|
|
-
|
378
|
|
-@@ -221,6 +235,10 @@ void ngx_cdecl ngx_log_debug_core(ngx_lo
|
379
|
|
-
|
380
|
|
- ngx_log_t *ngx_log_init(u_char *prefix);
|
381
|
|
- ngx_log_t *ngx_log_create(ngx_cycle_t *cycle, ngx_str_t *name);
|
382
|
|
-+#if (NGX_ENABLE_SYSLOG)
|
383
|
|
-+ngx_int_t ngx_log_get_priority(ngx_conf_t *cf, ngx_str_t *priority);
|
384
|
|
-+char * ngx_log_set_priority(ngx_conf_t *cf, ngx_str_t *priority, ngx_log_t *log);
|
385
|
|
-+#endif
|
386
|
|
- char *ngx_log_set_levels(ngx_conf_t *cf, ngx_log_t *log);
|
387
|
|
- void ngx_cdecl ngx_log_abort(ngx_err_t err, const char *fmt, ...);
|
388
|
|
- void ngx_cdecl ngx_log_stderr(ngx_err_t err, const char *fmt, ...);
|
389
|
|
-Index: nginx-1.4.7/src/http/modules/ngx_http_log_module.c
|
390
|
|
-===================================================================
|
391
|
|
---- nginx-1.4.7.orig/src/http/modules/ngx_http_log_module.c
|
392
|
|
-+++ nginx-1.4.7/src/http/modules/ngx_http_log_module.c
|
393
|
|
-@@ -13,6 +13,11 @@
|
394
|
|
- #include <zlib.h>
|
395
|
|
- #endif
|
396
|
|
-
|
397
|
|
-+#if (NGX_ENABLE_SYSLOG)
|
398
|
|
-+#include <syslog.h>
|
399
|
|
-+
|
400
|
|
-+#define HTTP_SYSLOG_PRIORITY LOG_NOTICE
|
401
|
|
-+#endif
|
402
|
|
-
|
403
|
|
- typedef struct ngx_http_log_op_s ngx_http_log_op_t;
|
404
|
|
-
|
405
|
|
-@@ -67,6 +72,11 @@ typedef struct {
|
406
|
|
- time_t disk_full_time;
|
407
|
|
- time_t error_log_time;
|
408
|
|
- ngx_http_log_fmt_t *format;
|
409
|
|
-+
|
410
|
|
-+#if (NGX_ENABLE_SYSLOG)
|
411
|
|
-+ ngx_int_t priority;
|
412
|
|
-+ unsigned syslog_on:1; /* unsigned :1 syslog_on */
|
413
|
|
-+#endif
|
414
|
|
- } ngx_http_log_t;
|
415
|
|
-
|
416
|
|
-
|
417
|
|
-@@ -348,6 +358,14 @@ ngx_http_log_write(ngx_http_request_t *r
|
418
|
|
- time_t now;
|
419
|
|
- ssize_t n;
|
420
|
|
- ngx_err_t err;
|
421
|
|
-+
|
422
|
|
-+#if (NGX_ENABLE_SYSLOG)
|
423
|
|
-+ n = 0;
|
424
|
|
-+ if (log->syslog_on) {
|
425
|
|
-+ syslog(log->priority, "%.*s", (int)len, buf);
|
426
|
|
-+ }
|
427
|
|
-+#endif
|
428
|
|
-+
|
429
|
|
- #if (NGX_ZLIB)
|
430
|
|
- ngx_http_log_buf_t *buffer;
|
431
|
|
- #endif
|
432
|
|
-@@ -355,6 +373,9 @@ ngx_http_log_write(ngx_http_request_t *r
|
433
|
|
- if (log->script == NULL) {
|
434
|
|
- name = log->file->name.data;
|
435
|
|
-
|
436
|
|
-+#if (NGX_ENABLE_SYSLOG)
|
437
|
|
-+ if (name != NULL) {
|
438
|
|
-+#endif
|
439
|
|
- #if (NGX_ZLIB)
|
440
|
|
- buffer = log->file->data;
|
441
|
|
-
|
442
|
|
-@@ -367,7 +388,11 @@ ngx_http_log_write(ngx_http_request_t *r
|
443
|
|
- #else
|
444
|
|
- n = ngx_write_fd(log->file->fd, buf, len);
|
445
|
|
- #endif
|
446
|
|
--
|
447
|
|
-+#if (NGX_ENABLE_SYSLOG)
|
448
|
|
-+ } else {
|
449
|
|
-+ n = len;
|
450
|
|
-+ }
|
451
|
|
-+#endif
|
452
|
|
- } else {
|
453
|
|
- name = NULL;
|
454
|
|
- n = ngx_http_log_script_write(r, log->script, &name, buf, len);
|
455
|
|
-@@ -1068,6 +1093,10 @@ ngx_http_log_merge_loc_conf(ngx_conf_t *
|
456
|
|
- log->script = NULL;
|
457
|
|
- log->disk_full_time = 0;
|
458
|
|
- log->error_log_time = 0;
|
459
|
|
-+#if (NGX_ENABLE_SYSLOG)
|
460
|
|
-+ log->priority = HTTP_SYSLOG_PRIORITY;
|
461
|
|
-+ log->syslog_on = 0;
|
462
|
|
-+#endif
|
463
|
|
-
|
464
|
|
- lmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_log_module);
|
465
|
|
- fmt = lmcf->formats.elts;
|
466
|
|
-@@ -1096,6 +1125,13 @@ ngx_http_log_set_log(ngx_conf_t *cf, ngx
|
467
|
|
- ngx_http_log_main_conf_t *lmcf;
|
468
|
|
- ngx_http_script_compile_t sc;
|
469
|
|
-
|
470
|
|
-+#if (NGX_ENABLE_SYSLOG)
|
471
|
|
-+ u_char *off;
|
472
|
|
-+ ngx_str_t priority;
|
473
|
|
-+ ngx_uint_t syslog_on = 0;
|
474
|
|
-+ name = priority = (ngx_str_t)ngx_null_string;
|
475
|
|
-+#endif
|
476
|
|
-+
|
477
|
|
- value = cf->args->elts;
|
478
|
|
-
|
479
|
|
- if (ngx_strcmp(value[1].data, "off") == 0) {
|
480
|
|
-@@ -1108,6 +1144,38 @@ ngx_http_log_set_log(ngx_conf_t *cf, ngx
|
481
|
|
- "invalid parameter \"%V\"", &value[2]);
|
482
|
|
- return NGX_CONF_ERROR;
|
483
|
|
- }
|
484
|
|
-+#if (NGX_ENABLE_SYSLOG)
|
485
|
|
-+ else if (ngx_strncmp(value[1].data, "syslog", sizeof("syslog") - 1) == 0) {
|
486
|
|
-+ if (!cf->cycle->new_log.syslog_set) {
|
487
|
|
-+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
488
|
|
-+ "You must set the syslog directive and enable it first.");
|
489
|
|
-+ return NGX_CONF_ERROR;
|
490
|
|
-+ }
|
491
|
|
-+
|
492
|
|
-+ syslog_on = 1;
|
493
|
|
-+ if (value[1].data[sizeof("syslog") - 1] == ':') {
|
494
|
|
-+ priority.len = value[1].len - sizeof("syslog");
|
495
|
|
-+ priority.data = value[1].data + sizeof("syslog");
|
496
|
|
-+
|
497
|
|
-+ off = (u_char*) ngx_strchr(priority.data, '|');
|
498
|
|
-+ if (off != NULL) {
|
499
|
|
-+ priority.len = off - priority.data;
|
500
|
|
-+
|
501
|
|
-+ off++;
|
502
|
|
-+ name.len = value[1].data + value[1].len - off;
|
503
|
|
-+ name.data = off;
|
504
|
|
-+ }
|
505
|
|
-+ }
|
506
|
|
-+ else {
|
507
|
|
-+ if (value[1].len > sizeof("syslog")) {
|
508
|
|
-+ name.len = value[1].len - sizeof("syslog");
|
509
|
|
-+ name.data = value[1].data + sizeof("syslog");
|
510
|
|
-+ }
|
511
|
|
-+ }
|
512
|
|
-+ } else {
|
513
|
|
-+ name = value[1];
|
514
|
|
-+ }
|
515
|
|
-+#endif
|
516
|
|
-
|
517
|
|
- if (llcf->logs == NULL) {
|
518
|
|
- llcf->logs = ngx_array_create(cf->pool, 2, sizeof(ngx_http_log_t));
|
519
|
|
-@@ -1125,6 +1193,52 @@ ngx_http_log_set_log(ngx_conf_t *cf, ngx
|
520
|
|
-
|
521
|
|
- ngx_memzero(log, sizeof(ngx_http_log_t));
|
522
|
|
-
|
523
|
|
-+#if (NGX_ENABLE_SYSLOG)
|
524
|
|
-+ log->syslog_on = syslog_on;
|
525
|
|
-+
|
526
|
|
-+ if (priority.len == 0) {
|
527
|
|
-+ log->priority = HTTP_SYSLOG_PRIORITY;
|
528
|
|
-+ }
|
529
|
|
-+ else {
|
530
|
|
-+ log->priority = ngx_log_get_priority(cf, &priority);
|
531
|
|
-+ }
|
532
|
|
-+
|
533
|
|
-+ if (name.len != 0) {
|
534
|
|
-+ n = ngx_http_script_variables_count(&name);
|
535
|
|
-+
|
536
|
|
-+ if (n == 0) {
|
537
|
|
-+ log->file = ngx_conf_open_file(cf->cycle, &name);
|
538
|
|
-+ if (log->file == NULL) {
|
539
|
|
-+ return NGX_CONF_ERROR;
|
540
|
|
-+ }
|
541
|
|
-+ } else {
|
542
|
|
-+ if (ngx_conf_full_name(cf->cycle, &name, 0) != NGX_OK) {
|
543
|
|
-+ return NGX_CONF_ERROR;
|
544
|
|
-+ }
|
545
|
|
-+ log->script = ngx_pcalloc(cf->pool, sizeof(ngx_http_log_script_t));
|
546
|
|
-+ if (log->script == NULL) {
|
547
|
|
-+ return NGX_CONF_ERROR;
|
548
|
|
-+ }
|
549
|
|
-+ ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
|
550
|
|
-+ sc.cf = cf;
|
551
|
|
-+ sc.source = &name;
|
552
|
|
-+ sc.lengths = &log->script->lengths;
|
553
|
|
-+ sc.values = &log->script->values;
|
554
|
|
-+ sc.variables = n;
|
555
|
|
-+ sc.complete_lengths = 1;
|
556
|
|
-+ sc.complete_values = 1;
|
557
|
|
-+ if (ngx_http_script_compile(&sc) != NGX_OK) {
|
558
|
|
-+ return NGX_CONF_ERROR;
|
559
|
|
-+ }
|
560
|
|
-+ }
|
561
|
|
-+ }
|
562
|
|
-+ else {
|
563
|
|
-+ log->file = ngx_conf_open_file(cf->cycle, &name);
|
564
|
|
-+ if (log->file == NULL) {
|
565
|
|
-+ return NGX_CONF_ERROR;
|
566
|
|
-+ }
|
567
|
|
-+ }
|
568
|
|
-+#else
|
569
|
|
- n = ngx_http_script_variables_count(&value[1]);
|
570
|
|
-
|
571
|
|
- if (n == 0) {
|
572
|
|
-@@ -1157,6 +1271,7 @@ ngx_http_log_set_log(ngx_conf_t *cf, ngx
|
573
|
|
- return NGX_CONF_ERROR;
|
574
|
|
- }
|
575
|
|
- }
|
576
|
|
-+#endif
|
577
|
|
-
|
578
|
|
- if (cf->args->nelts >= 3) {
|
579
|
|
- name = value[2];
|
580
|
|
-Index: nginx-1.4.7/src/http/ngx_http_core_module.c
|
581
|
|
-===================================================================
|
582
|
|
---- nginx-1.4.7.orig/src/http/ngx_http_core_module.c
|
583
|
|
-+++ nginx-1.4.7/src/http/ngx_http_core_module.c
|
584
|
|
-@@ -1462,6 +1462,9 @@ ngx_http_update_location_config(ngx_http
|
585
|
|
-
|
586
|
|
- if (r == r->main) {
|
587
|
|
- ngx_http_set_connection_log(r->connection, clcf->error_log);
|
588
|
|
-+#if (NGX_ENABLE_SYSLOG)
|
589
|
|
-+ r->connection->log->priority = clcf->error_log->priority;
|
590
|
|
-+#endif
|
591
|
|
- }
|
592
|
|
-
|
593
|
|
- if ((ngx_io.flags & NGX_IO_SENDFILE) && clcf->sendfile) {
|
594
|
|
-@@ -4901,6 +4904,15 @@ ngx_http_core_error_log(ngx_conf_t *cf,
|
595
|
|
-
|
596
|
|
- ngx_str_t *value, name;
|
597
|
|
-
|
598
|
|
-+#if (NGX_ENABLE_SYSLOG)
|
599
|
|
-+ u_char *off = NULL;
|
600
|
|
-+ ngx_int_t syslog_on = 0;
|
601
|
|
-+ ngx_str_t priority;
|
602
|
|
-+
|
603
|
|
-+ name = priority = (ngx_str_t) ngx_null_string;
|
604
|
|
-+#endif
|
605
|
|
-+
|
606
|
|
-+
|
607
|
|
- if (clcf->error_log) {
|
608
|
|
- return "is duplicate";
|
609
|
|
- }
|
610
|
|
-@@ -4910,6 +4922,36 @@ ngx_http_core_error_log(ngx_conf_t *cf,
|
611
|
|
- if (ngx_strcmp(value[1].data, "stderr") == 0) {
|
612
|
|
- ngx_str_null(&name);
|
613
|
|
-
|
614
|
|
-+#if (NGX_ENABLE_SYSLOG)
|
615
|
|
-+ } else if (ngx_strncmp(value[1].data, "syslog", sizeof("syslog") - 1) == 0) {
|
616
|
|
-+ if (!cf->cycle->new_log.syslog_set) {
|
617
|
|
-+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
618
|
|
-+ "You must set the syslog directive and enable it first.");
|
619
|
|
-+ return NGX_CONF_ERROR;
|
620
|
|
-+ }
|
621
|
|
-+
|
622
|
|
-+ syslog_on = 1;
|
623
|
|
-+
|
624
|
|
-+ if (value[1].data[sizeof("syslog") - 1] == ':') {
|
625
|
|
-+ priority.len = value[1].len - sizeof("syslog");
|
626
|
|
-+ priority.data = value[1].data + sizeof("syslog");
|
627
|
|
-+
|
628
|
|
-+ off = (u_char*) ngx_strchr(priority.data, '|');
|
629
|
|
-+ if (off != NULL) {
|
630
|
|
-+ priority.len = off - priority.data;
|
631
|
|
-+
|
632
|
|
-+ off++;
|
633
|
|
-+ name.len = value[1].data + value[1].len - off;
|
634
|
|
-+ name.data = off;
|
635
|
|
-+ }
|
636
|
|
-+ }
|
637
|
|
-+ else {
|
638
|
|
-+ if (value[1].len > sizeof("syslog")) {
|
639
|
|
-+ name.len = value[1].len - sizeof("syslog");
|
640
|
|
-+ name.data = value[1].data + sizeof("syslog");
|
641
|
|
-+ }
|
642
|
|
-+ }
|
643
|
|
-+#endif
|
644
|
|
- } else {
|
645
|
|
- name = value[1];
|
646
|
|
- }
|
647
|
|
-@@ -4919,6 +4961,17 @@ ngx_http_core_error_log(ngx_conf_t *cf,
|
648
|
|
- return NGX_CONF_ERROR;
|
649
|
|
- }
|
650
|
|
-
|
651
|
|
-+#if (NGX_ENABLE_SYSLOG)
|
652
|
|
-+ if (syslog_on) {
|
653
|
|
-+ clcf->error_log->syslog_on = 1;
|
654
|
|
-+ if (ngx_log_set_priority(cf, &priority, clcf->error_log) == NGX_CONF_ERROR) {
|
655
|
|
-+ return NGX_CONF_ERROR;
|
656
|
|
-+ }
|
657
|
|
-+ }
|
658
|
|
-+
|
659
|
|
-+ clcf->error_log->log_level = 0;
|
660
|
|
-+#endif
|
661
|
|
-+
|
662
|
|
- if (cf->args->nelts == 2) {
|
663
|
|
- clcf->error_log->log_level = NGX_LOG_ERR;
|
664
|
|
- return NGX_CONF_OK;
|
665
|
|
-Index: nginx-1.4.7/src/http/ngx_http_request.c
|
666
|
|
-===================================================================
|
667
|
|
---- nginx-1.4.7.orig/src/http/ngx_http_request.c
|
668
|
|
-+++ nginx-1.4.7/src/http/ngx_http_request.c
|
669
|
|
-@@ -533,6 +533,9 @@ ngx_http_create_request(ngx_connection_t
|
670
|
|
- clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
671
|
|
-
|
672
|
|
- ngx_http_set_connection_log(r->connection, clcf->error_log);
|
673
|
|
-+#if (NGX_ENABLE_SYSLOG)
|
674
|
|
-+ c->log->priority = clcf->error_log->priority;
|
675
|
|
-+#endif
|
676
|
|
-
|
677
|
|
- r->header_in = hc->nbusy ? hc->busy[0] : c->buffer;
|
678
|
|
-
|
679
|
|
-@@ -872,6 +875,9 @@ ngx_http_ssl_servername(ngx_ssl_conn_t *
|
680
|
|
- clcf = ngx_http_get_module_loc_conf(hc->conf_ctx, ngx_http_core_module);
|
681
|
|
-
|
682
|
|
- ngx_http_set_connection_log(c, clcf->error_log);
|
683
|
|
-+#if (NGX_ENABLE_SYSLOG)
|
684
|
|
-+ c->log->priority = clcf->error_log->priority;
|
685
|
|
-+#endif
|
686
|
|
-
|
687
|
|
- sscf = ngx_http_get_module_srv_conf(hc->conf_ctx, ngx_http_ssl_module);
|
688
|
|
-
|
689
|
|
-@@ -2077,6 +2083,9 @@ ngx_http_set_virtual_server(ngx_http_req
|
690
|
|
- clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
691
|
|
-
|
692
|
|
- ngx_http_set_connection_log(r->connection, clcf->error_log);
|
693
|
|
-+#if (NGX_ENABLE_SYSLOG)
|
694
|
|
-+ r->connection->log->priority = clcf->error_log->priority;
|
695
|
|
-+#endif
|
696
|
|
-
|
697
|
|
- return NGX_OK;
|
698
|
|
- }
|