-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathngx_log_early.patch
78 lines (67 loc) · 2.07 KB
/
ngx_log_early.patch
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
--- a/src/http/modules/ngx_http_log_module.c
+++ b/src/http/modules/ngx_http_log_module.c
@@ -69,6 +69,7 @@ typedef struct {
ngx_syslog_peer_t *syslog_peer;
ngx_http_log_fmt_t *format;
ngx_http_complex_value_t *filter;
+ ngx_flag_t early;
} ngx_http_log_t;
@@ -251,7 +252,7 @@ static ngx_http_log_var_t ngx_http_log_vars[] = {
static ngx_int_t
-ngx_http_log_handler(ngx_http_request_t *r)
+ngx_http_log_handler(ngx_http_request_t *r, ngx_flag_t early)
{
u_char *line, *p;
size_t len, size;
@@ -275,6 +276,10 @@ ngx_http_log_handler(ngx_http_request_t *r)
log = lcf->logs->elts;
for (l = 0; l < lcf->logs->nelts; l++) {
+ if (log[l].early != early) {
+ continue;
+ }
+
if (log[l].filter) {
if (ngx_http_complex_value(r, log[l].filter, &val) != NGX_OK) {
return NGX_ERROR;
@@ -402,6 +407,20 @@ ngx_http_log_handler(ngx_http_request_t *r)
}
+static ngx_int_t
+ngx_http_early_log_handler(ngx_http_request_t *r)
+{
+ return ngx_http_log_handler(r, 1);
+}
+
+
+static ngx_int_t
+ngx_http_standard_log_handler(ngx_http_request_t *r)
+{
+ return ngx_http_log_handler(r, 0);
+}
+
+
static void
ngx_http_log_write(ngx_http_request_t *r, ngx_http_log_t *log, u_char *buf,
size_t len)
@@ -1367,6 +1386,11 @@ process_formats:
for (i = 3; i < cf->args->nelts; i++) {
+ if (ngx_strncmp(value[i].data, "early", 5) == 0) {
+ log->early = 1;
+ continue;
+ }
+
if (ngx_strncmp(value[i].data, "buffer=", 7) == 0) {
s.len = value[i].len - 7;
s.data = value[i].data + 7;
@@ -1902,8 +1926,13 @@ ngx_http_log_init(ngx_conf_t *cf)
if (h == NULL) {
return NGX_ERROR;
}
+ *h = ngx_http_standard_log_handler;
- *h = ngx_http_log_handler;
+ h = ngx_array_push(&cmcf->phases[NGX_HTTP_POST_READ_PHASE].handlers);
+ if (h == NULL) {
+ return NGX_ERROR;
+ }
+ *h = ngx_http_early_log_handler;
return NGX_OK;
}