Mercurial > hg > nginx
annotate src/http/modules/ngx_http_log_module.c @ 6927:c36d160cd4e0
Access log: removed dead ev->timedout check in flush timer handler.
The ev->timedout flag is set on first timer expiration, and never reset
after it. Due to this the code to stop the timer when the timer was
canceled never worked (except in a very specific time frame immediately
after start), and the timer was always armed again. This essentially
resulted in a buffer flush at the end of an event loop iteration.
This behaviour actually seems to be better than just stopping the flush
timer for the whole shutdown, so it is preserved as is instead of fixing
the code to actually remove the timer. It will be further improved by
upcoming changes to preserve cancelable timers if there are other timers
blocking shutdown.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Tue, 07 Mar 2017 18:51:12 +0300 |
parents | 0cf4e82e7c48 |
children | 3fb9b5eb75c0 |
rev | line source |
---|---|
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
427
diff
changeset
|
1 |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
427
diff
changeset
|
2 /* |
444
42d11f017717
nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents:
441
diff
changeset
|
3 * Copyright (C) Igor Sysoev |
4412 | 4 * Copyright (C) Nginx, Inc. |
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
427
diff
changeset
|
5 */ |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
427
diff
changeset
|
6 |
26
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 |
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 #include <ngx_config.h> |
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
9 #include <ngx_core.h> |
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
10 #include <ngx_http.h> |
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
11 |
4988
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
12 #if (NGX_ZLIB) |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
13 #include <zlib.h> |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
14 #endif |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
15 |
26
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
16 |
880 | 17 typedef struct ngx_http_log_op_s ngx_http_log_op_t; |
18 | |
19 typedef u_char *(*ngx_http_log_op_run_pt) (ngx_http_request_t *r, u_char *buf, | |
20 ngx_http_log_op_t *op); | |
21 | |
22 typedef size_t (*ngx_http_log_op_getlen_pt) (ngx_http_request_t *r, | |
23 uintptr_t data); | |
24 | |
25 | |
26 struct ngx_http_log_op_s { | |
27 size_t len; | |
28 ngx_http_log_op_getlen_pt getlen; | |
29 ngx_http_log_op_run_pt run; | |
30 uintptr_t data; | |
31 }; | |
32 | |
573 | 33 |
34 typedef struct { | |
35 ngx_str_t name; | |
2261 | 36 ngx_array_t *flushes; |
573 | 37 ngx_array_t *ops; /* array of ngx_http_log_op_t */ |
38 } ngx_http_log_fmt_t; | |
39 | |
657 | 40 |
573 | 41 typedef struct { |
42 ngx_array_t formats; /* array of ngx_http_log_fmt_t */ | |
43 ngx_uint_t combined_used; /* unsigned combined_used:1 */ | |
44 } ngx_http_log_main_conf_t; | |
45 | |
657 | 46 |
573 | 47 typedef struct { |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
48 u_char *start; |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
49 u_char *pos; |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
50 u_char *last; |
4986
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
51 |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
52 ngx_event_t *event; |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
53 ngx_msec_t flush; |
4988
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
54 ngx_int_t gzip; |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
55 } ngx_http_log_buf_t; |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
56 |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
57 |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
58 typedef struct { |
2072 | 59 ngx_array_t *lengths; |
60 ngx_array_t *values; | |
61 } ngx_http_log_script_t; | |
62 | |
63 | |
64 typedef struct { | |
573 | 65 ngx_open_file_t *file; |
2072 | 66 ngx_http_log_script_t *script; |
633 | 67 time_t disk_full_time; |
1071
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
68 time_t error_log_time; |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
69 ngx_syslog_peer_t *syslog_peer; |
2261 | 70 ngx_http_log_fmt_t *format; |
5653
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
71 ngx_http_complex_value_t *filter; |
573 | 72 } ngx_http_log_t; |
73 | |
657 | 74 |
573 | 75 typedef struct { |
76 ngx_array_t *logs; /* array of ngx_http_log_t */ | |
2072 | 77 |
78 ngx_open_file_cache_t *open_file_cache; | |
79 time_t open_file_cache_valid; | |
80 ngx_uint_t open_file_cache_min_uses; | |
81 | |
573 | 82 ngx_uint_t off; /* unsigned off:1 */ |
83 } ngx_http_log_loc_conf_t; | |
84 | |
85 | |
86 typedef struct { | |
87 ngx_str_t name; | |
88 size_t len; | |
89 ngx_http_log_op_run_pt run; | |
90 } ngx_http_log_var_t; | |
91 | |
92 | |
1071
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
93 static void ngx_http_log_write(ngx_http_request_t *r, ngx_http_log_t *log, |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
94 u_char *buf, size_t len); |
2072 | 95 static ssize_t ngx_http_log_script_write(ngx_http_request_t *r, |
96 ngx_http_log_script_t *script, u_char **name, u_char *buf, size_t len); | |
1071
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
97 |
4988
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
98 #if (NGX_ZLIB) |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
99 static ssize_t ngx_http_log_gzip(ngx_fd_t fd, u_char *buf, size_t len, |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
100 ngx_int_t level, ngx_log_t *log); |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
101 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
102 static void *ngx_http_log_gzip_alloc(void *opaque, u_int items, u_int size); |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
103 static void ngx_http_log_gzip_free(void *opaque, void *address); |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
104 #endif |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
105 |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
106 static void ngx_http_log_flush(ngx_open_file_t *file, ngx_log_t *log); |
4986
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
107 static void ngx_http_log_flush_handler(ngx_event_t *ev); |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
108 |
290
87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
282
diff
changeset
|
109 static u_char *ngx_http_log_pipe(ngx_http_request_t *r, u_char *buf, |
497 | 110 ngx_http_log_op_t *op); |
290
87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
282
diff
changeset
|
111 static u_char *ngx_http_log_time(ngx_http_request_t *r, u_char *buf, |
497 | 112 ngx_http_log_op_t *op); |
3873 | 113 static u_char *ngx_http_log_iso8601(ngx_http_request_t *r, u_char *buf, |
114 ngx_http_log_op_t *op); | |
409
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
393
diff
changeset
|
115 static u_char *ngx_http_log_msec(ngx_http_request_t *r, u_char *buf, |
497 | 116 ngx_http_log_op_t *op); |
117 static u_char *ngx_http_log_request_time(ngx_http_request_t *r, u_char *buf, | |
118 ngx_http_log_op_t *op); | |
290
87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
282
diff
changeset
|
119 static u_char *ngx_http_log_status(ngx_http_request_t *r, u_char *buf, |
497 | 120 ngx_http_log_op_t *op); |
573 | 121 static u_char *ngx_http_log_bytes_sent(ngx_http_request_t *r, u_char *buf, |
497 | 122 ngx_http_log_op_t *op); |
577 | 123 static u_char *ngx_http_log_body_bytes_sent(ngx_http_request_t *r, |
573 | 124 u_char *buf, ngx_http_log_op_t *op); |
475 | 125 static u_char *ngx_http_log_request_length(ngx_http_request_t *r, u_char *buf, |
497 | 126 ngx_http_log_op_t *op); |
479 | 127 |
501 | 128 static ngx_int_t ngx_http_log_variable_compile(ngx_conf_t *cf, |
6840
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
129 ngx_http_log_op_t *op, ngx_str_t *value, ngx_uint_t json); |
501 | 130 static size_t ngx_http_log_variable_getlen(ngx_http_request_t *r, |
131 uintptr_t data); | |
132 static u_char *ngx_http_log_variable(ngx_http_request_t *r, u_char *buf, | |
133 ngx_http_log_op_t *op); | |
2008
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
134 static uintptr_t ngx_http_log_escape(u_char *dst, u_char *src, size_t size); |
6840
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
135 static size_t ngx_http_log_json_variable_getlen(ngx_http_request_t *r, |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
136 uintptr_t data); |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
137 static u_char *ngx_http_log_json_variable(ngx_http_request_t *r, u_char *buf, |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
138 ngx_http_log_op_t *op); |
501 | 139 |
140 | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
141 static void *ngx_http_log_create_main_conf(ngx_conf_t *cf); |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
142 static void *ngx_http_log_create_loc_conf(ngx_conf_t *cf); |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
143 static char *ngx_http_log_merge_loc_conf(ngx_conf_t *cf, void *parent, |
497 | 144 void *child); |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
145 static char *ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd, |
497 | 146 void *conf); |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
147 static char *ngx_http_log_set_format(ngx_conf_t *cf, ngx_command_t *cmd, |
497 | 148 void *conf); |
573 | 149 static char *ngx_http_log_compile_format(ngx_conf_t *cf, |
2261 | 150 ngx_array_t *flushes, ngx_array_t *ops, ngx_array_t *args, ngx_uint_t s); |
2072 | 151 static char *ngx_http_log_open_file_cache(ngx_conf_t *cf, ngx_command_t *cmd, |
152 void *conf); | |
573 | 153 static ngx_int_t ngx_http_log_init(ngx_conf_t *cf); |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
154 |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
155 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
156 static ngx_command_t ngx_http_log_commands[] = { |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
157 |
497 | 158 { ngx_string("log_format"), |
5927
ac2a8e4d8f01
Access log: restricted "log_format" to "http" level.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5897
diff
changeset
|
159 NGX_HTTP_MAIN_CONF|NGX_CONF_2MORE, |
497 | 160 ngx_http_log_set_format, |
161 NGX_HTTP_MAIN_CONF_OFFSET, | |
162 0, | |
163 NULL }, | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
164 |
497 | 165 { ngx_string("access_log"), |
645 | 166 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF |
4986
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
167 |NGX_HTTP_LMT_CONF|NGX_CONF_1MORE, |
497 | 168 ngx_http_log_set_log, |
169 NGX_HTTP_LOC_CONF_OFFSET, | |
170 0, | |
171 NULL }, | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
172 |
2072 | 173 { ngx_string("open_log_file_cache"), |
174 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1234, | |
175 ngx_http_log_open_file_cache, | |
176 NGX_HTTP_LOC_CONF_OFFSET, | |
177 0, | |
178 NULL }, | |
179 | |
497 | 180 ngx_null_command |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
181 }; |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
182 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
183 |
667 | 184 static ngx_http_module_t ngx_http_log_module_ctx = { |
880 | 185 NULL, /* preconfiguration */ |
573 | 186 ngx_http_log_init, /* postconfiguration */ |
177
4db54fdbcbe7
nginx-0.0.1-2003-11-10-20:17:31 import
Igor Sysoev <igor@sysoev.ru>
parents:
176
diff
changeset
|
187 |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
188 ngx_http_log_create_main_conf, /* create main configuration */ |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
189 NULL, /* init main configuration */ |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
190 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
191 NULL, /* create server configuration */ |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
192 NULL, /* merge server configuration */ |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
193 |
4499
778ef9c3fd2d
Fixed spelling in single-line comments.
Ruslan Ermilov <ru@nginx.com>
parents:
4494
diff
changeset
|
194 ngx_http_log_create_loc_conf, /* create location configuration */ |
778ef9c3fd2d
Fixed spelling in single-line comments.
Ruslan Ermilov <ru@nginx.com>
parents:
4494
diff
changeset
|
195 ngx_http_log_merge_loc_conf /* merge location configuration */ |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
196 }; |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
197 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
198 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
199 ngx_module_t ngx_http_log_module = { |
509 | 200 NGX_MODULE_V1, |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
201 &ngx_http_log_module_ctx, /* module context */ |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
202 ngx_http_log_commands, /* module directives */ |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
203 NGX_HTTP_MODULE, /* module type */ |
541 | 204 NULL, /* init master */ |
573 | 205 NULL, /* init module */ |
541 | 206 NULL, /* init process */ |
207 NULL, /* init thread */ | |
208 NULL, /* exit thread */ | |
209 NULL, /* exit process */ | |
210 NULL, /* exit master */ | |
211 NGX_MODULE_V1_PADDING | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
212 }; |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
213 |
26
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
214 |
1074 | 215 static ngx_str_t ngx_http_access_log = ngx_string(NGX_HTTP_LOG_PATH); |
573 | 216 |
217 | |
218 static ngx_str_t ngx_http_combined_fmt = | |
581 | 219 ngx_string("$remote_addr - $remote_user [$time_local] " |
577 | 220 "\"$request\" $status $body_bytes_sent " |
573 | 221 "\"$http_referer\" \"$http_user_agent\""); |
119
cd54bcbaf3b5
nginx-0.0.1-2003-07-21-01:15:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
116
diff
changeset
|
222 |
26
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
223 |
573 | 224 static ngx_http_log_var_t ngx_http_log_vars[] = { |
225 { ngx_string("pipe"), 1, ngx_http_log_pipe }, | |
581 | 226 { ngx_string("time_local"), sizeof("28/Sep/1970:12:00:00 +0600") - 1, |
573 | 227 ngx_http_log_time }, |
3873 | 228 { ngx_string("time_iso8601"), sizeof("1970-09-28T12:00:00+06:00") - 1, |
229 ngx_http_log_iso8601 }, | |
573 | 230 { ngx_string("msec"), NGX_TIME_T_LEN + 4, ngx_http_log_msec }, |
1179
6e2216ad2c87
$request_time has millisecond precision
Igor Sysoev <igor@sysoev.ru>
parents:
1161
diff
changeset
|
231 { ngx_string("request_time"), NGX_TIME_T_LEN + 4, |
6e2216ad2c87
$request_time has millisecond precision
Igor Sysoev <igor@sysoev.ru>
parents:
1161
diff
changeset
|
232 ngx_http_log_request_time }, |
4637
668ab1a21327
Zero padded the returned and logged HTTP status code, and fixed possible
Ruslan Ermilov <ru@nginx.com>
parents:
4539
diff
changeset
|
233 { ngx_string("status"), NGX_INT_T_LEN, ngx_http_log_status }, |
573 | 234 { ngx_string("bytes_sent"), NGX_OFF_T_LEN, ngx_http_log_bytes_sent }, |
577 | 235 { ngx_string("body_bytes_sent"), NGX_OFF_T_LEN, |
236 ngx_http_log_body_bytes_sent }, | |
573 | 237 { ngx_string("request_length"), NGX_SIZE_T_LEN, |
238 ngx_http_log_request_length }, | |
239 | |
240 { ngx_null_string, 0, NULL } | |
241 }; | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
242 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
243 |
4759
4c36e15651f7
Fixed compilation with -Wmissing-prototypes.
Ruslan Ermilov <ru@nginx.com>
parents:
4685
diff
changeset
|
244 static ngx_int_t |
497 | 245 ngx_http_log_handler(ngx_http_request_t *r) |
26
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
246 { |
290
87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
282
diff
changeset
|
247 u_char *line, *p; |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
248 size_t len, size; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
249 ssize_t n; |
5653
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
250 ngx_str_t val; |
1071
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
251 ngx_uint_t i, l; |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
252 ngx_http_log_t *log; |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
253 ngx_http_log_op_t *op; |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
254 ngx_http_log_buf_t *buffer; |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
255 ngx_http_log_loc_conf_t *lcf; |
26
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
256 |
210
00cafae0bdf1
nginx-0.0.1-2003-12-14-23:10:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
257 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
00cafae0bdf1
nginx-0.0.1-2003-12-14-23:10:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
258 "http log handler"); |
28
a117a7fdf042
nginx-0.0.1-2002-12-16-00:08:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
26
diff
changeset
|
259 |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
260 lcf = ngx_http_get_module_loc_conf(r, ngx_http_log_module); |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
261 |
427
0d08eabe5c7b
nginx-0.0.10-2004-09-15-20:00:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
262 if (lcf->off) { |
0d08eabe5c7b
nginx-0.0.10-2004-09-15-20:00:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
263 return NGX_OK; |
0d08eabe5c7b
nginx-0.0.10-2004-09-15-20:00:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
264 } |
0d08eabe5c7b
nginx-0.0.10-2004-09-15-20:00:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
265 |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
266 log = lcf->logs->elts; |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
267 for (l = 0; l < lcf->logs->nelts; l++) { |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
268 |
5653
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
269 if (log[l].filter) { |
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
270 if (ngx_http_complex_value(r, log[l].filter, &val) != NGX_OK) { |
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
271 return NGX_ERROR; |
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
272 } |
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
273 |
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
274 if (val.len == 0 || (val.len == 1 && val.data[0] == '0')) { |
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
275 continue; |
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
276 } |
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
277 } |
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
278 |
633 | 279 if (ngx_time() == log[l].disk_full_time) { |
280 | |
281 /* | |
1071
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
282 * on FreeBSD writing to a full filesystem with enabled softupdates |
633 | 283 * may block process for much longer time than writing to non-full |
1071
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
284 * filesystem, so we skip writing to a log for one second |
633 | 285 */ |
286 | |
287 continue; | |
288 } | |
289 | |
2261 | 290 ngx_http_script_flush_no_cacheable_variables(r, log[l].format->flushes); |
291 | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
292 len = 0; |
2261 | 293 op = log[l].format->ops->elts; |
294 for (i = 0; i < log[l].format->ops->nelts; i++) { | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
295 if (op[i].len == 0) { |
479 | 296 len += op[i].getlen(r, op[i].data); |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
297 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
298 } else { |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
299 len += op[i].len; |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
300 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
301 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
302 |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
303 if (log[l].syslog_peer) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
304 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
305 /* length of syslog's PRI and HEADER message parts */ |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
306 len += sizeof("<255>Jan 01 00:00:00 ") - 1 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
307 + ngx_cycle->hostname.len + 1 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
308 + log[l].syslog_peer->tag.len + 2; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
309 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
310 goto alloc_line; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
311 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
312 |
571 | 313 len += NGX_LINEFEED_SIZE; |
314 | |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
315 buffer = log[l].file ? log[l].file->data : NULL; |
571 | 316 |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
317 if (buffer) { |
571 | 318 |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
319 if (len > (size_t) (buffer->last - buffer->pos)) { |
571 | 320 |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
321 ngx_http_log_write(r, &log[l], buffer->start, |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
322 buffer->pos - buffer->start); |
571 | 323 |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
324 buffer->pos = buffer->start; |
571 | 325 } |
326 | |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
327 if (len <= (size_t) (buffer->last - buffer->pos)) { |
571 | 328 |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
329 p = buffer->pos; |
571 | 330 |
4986
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
331 if (buffer->event && p == buffer->start) { |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
332 ngx_add_timer(buffer->event, buffer->flush); |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
333 } |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
334 |
2261 | 335 for (i = 0; i < log[l].format->ops->nelts; i++) { |
571 | 336 p = op[i].run(r, p, &op[i]); |
337 } | |
338 | |
339 ngx_linefeed(p); | |
340 | |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
341 buffer->pos = p; |
571 | 342 |
343 continue; | |
344 } | |
4986
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
345 |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
346 if (buffer->event && buffer->event->timer_set) { |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
347 ngx_del_timer(buffer->event); |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
348 } |
571 | 349 } |
26
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
350 |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
351 alloc_line: |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
352 |
2049 | 353 line = ngx_pnalloc(r->pool, len); |
501 | 354 if (line == NULL) { |
473 | 355 return NGX_ERROR; |
356 } | |
357 | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
358 p = line; |
26
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
359 |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
360 if (log[l].syslog_peer) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
361 p = ngx_syslog_add_header(log[l].syslog_peer, line); |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
362 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
363 |
2261 | 364 for (i = 0; i < log[l].format->ops->nelts; i++) { |
479 | 365 p = op[i].run(r, p, &op[i]); |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
366 } |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
367 |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
368 if (log[l].syslog_peer) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
369 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
370 size = p - line; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
371 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
372 n = ngx_syslog_send(log[l].syslog_peer, line, size); |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
373 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
374 if (n < 0) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
375 ngx_log_error(NGX_LOG_WARN, r->connection->log, 0, |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
376 "send() to syslog failed"); |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
377 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
378 } else if ((size_t) n != size) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
379 ngx_log_error(NGX_LOG_WARN, r->connection->log, 0, |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
380 "send() to syslog has written only %z of %uz", |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
381 n, size); |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
382 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
383 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
384 continue; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
385 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
386 |
571 | 387 ngx_linefeed(p); |
388 | |
1071
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
389 ngx_http_log_write(r, &log[l], line, p - line); |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
390 } |
26
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
391 |
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
392 return NGX_OK; |
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
393 } |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
394 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
395 |
1071
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
396 static void |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
397 ngx_http_log_write(ngx_http_request_t *r, ngx_http_log_t *log, u_char *buf, |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
398 size_t len) |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
399 { |
4988
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
400 u_char *name; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
401 time_t now; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
402 ssize_t n; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
403 ngx_err_t err; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
404 #if (NGX_ZLIB) |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
405 ngx_http_log_buf_t *buffer; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
406 #endif |
1071
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
407 |
2072 | 408 if (log->script == NULL) { |
409 name = log->file->name.data; | |
4988
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
410 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
411 #if (NGX_ZLIB) |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
412 buffer = log->file->data; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
413 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
414 if (buffer && buffer->gzip) { |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
415 n = ngx_http_log_gzip(log->file->fd, buf, len, buffer->gzip, |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
416 r->connection->log); |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
417 } else { |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
418 n = ngx_write_fd(log->file->fd, buf, len); |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
419 } |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
420 #else |
2072 | 421 n = ngx_write_fd(log->file->fd, buf, len); |
4988
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
422 #endif |
2072 | 423 |
424 } else { | |
425 name = NULL; | |
426 n = ngx_http_log_script_write(r, log->script, &name, buf, len); | |
427 } | |
1071
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
428 |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
429 if (n == (ssize_t) len) { |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
430 return; |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
431 } |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
432 |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
433 now = ngx_time(); |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
434 |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
435 if (n == -1) { |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
436 err = ngx_errno; |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
437 |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
438 if (err == NGX_ENOSPC) { |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
439 log->disk_full_time = now; |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
440 } |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
441 |
1161
6002e0253221
use 60 seconds interval but not 61 seconds
Igor Sysoev <igor@sysoev.ru>
parents:
1074
diff
changeset
|
442 if (now - log->error_log_time > 59) { |
1071
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
443 ngx_log_error(NGX_LOG_ALERT, r->connection->log, err, |
2072 | 444 ngx_write_fd_n " to \"%s\" failed", name); |
1071
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
445 |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
446 log->error_log_time = now; |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
447 } |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
448 |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
449 return; |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
450 } |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
451 |
1161
6002e0253221
use 60 seconds interval but not 61 seconds
Igor Sysoev <igor@sysoev.ru>
parents:
1074
diff
changeset
|
452 if (now - log->error_log_time > 59) { |
1071
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
453 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, |
2072 | 454 ngx_write_fd_n " to \"%s\" was incomplete: %z of %uz", |
455 name, n, len); | |
1071
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
456 |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
457 log->error_log_time = now; |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
458 } |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
459 } |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
460 |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
461 |
2072 | 462 static ssize_t |
463 ngx_http_log_script_write(ngx_http_request_t *r, ngx_http_log_script_t *script, | |
464 u_char **name, u_char *buf, size_t len) | |
465 { | |
466 size_t root; | |
467 ssize_t n; | |
468 ngx_str_t log, path; | |
469 ngx_open_file_info_t of; | |
470 ngx_http_log_loc_conf_t *llcf; | |
471 ngx_http_core_loc_conf_t *clcf; | |
472 | |
4478
08713bac87fc
Support for disable_symlinks in various modules.
Andrey Belov <defan@nginx.com>
parents:
4474
diff
changeset
|
473 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
08713bac87fc
Support for disable_symlinks in various modules.
Andrey Belov <defan@nginx.com>
parents:
4474
diff
changeset
|
474 |
2087
c8039b26a949
always test root existence for access_log with variables
Igor Sysoev <igor@sysoev.ru>
parents:
2080
diff
changeset
|
475 if (!r->root_tested) { |
2072 | 476 |
4499
778ef9c3fd2d
Fixed spelling in single-line comments.
Ruslan Ermilov <ru@nginx.com>
parents:
4494
diff
changeset
|
477 /* test root directory existence */ |
2072 | 478 |
479 if (ngx_http_map_uri_to_path(r, &path, &root, 0) == NULL) { | |
4499
778ef9c3fd2d
Fixed spelling in single-line comments.
Ruslan Ermilov <ru@nginx.com>
parents:
4494
diff
changeset
|
480 /* simulate successful logging */ |
2072 | 481 return len; |
482 } | |
483 | |
484 path.data[root] = '\0'; | |
485 | |
486 ngx_memzero(&of, sizeof(ngx_open_file_info_t)); | |
487 | |
488 of.valid = clcf->open_file_cache_valid; | |
489 of.min_uses = clcf->open_file_cache_min_uses; | |
2756
09cab3f8d92e
*) of.test_only to not open file if only stat() is enough
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
490 of.test_dir = 1; |
09cab3f8d92e
*) of.test_only to not open file if only stat() is enough
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
491 of.test_only = 1; |
2072 | 492 of.errors = clcf->open_file_cache_errors; |
493 of.events = clcf->open_file_cache_events; | |
4494
13e09cf11d4e
Disable symlinks: initialization of the "disable_symlinks" field in
Valentin Bartenev <vbart@nginx.com>
parents:
4478
diff
changeset
|
494 |
13e09cf11d4e
Disable symlinks: initialization of the "disable_symlinks" field in
Valentin Bartenev <vbart@nginx.com>
parents:
4478
diff
changeset
|
495 if (ngx_http_set_disable_symlinks(r, clcf, &path, &of) != NGX_OK) { |
13e09cf11d4e
Disable symlinks: initialization of the "disable_symlinks" field in
Valentin Bartenev <vbart@nginx.com>
parents:
4478
diff
changeset
|
496 /* simulate successful logging */ |
13e09cf11d4e
Disable symlinks: initialization of the "disable_symlinks" field in
Valentin Bartenev <vbart@nginx.com>
parents:
4478
diff
changeset
|
497 return len; |
13e09cf11d4e
Disable symlinks: initialization of the "disable_symlinks" field in
Valentin Bartenev <vbart@nginx.com>
parents:
4478
diff
changeset
|
498 } |
2072 | 499 |
500 if (ngx_open_cached_file(clcf->open_file_cache, &path, &of, r->pool) | |
2087
c8039b26a949
always test root existence for access_log with variables
Igor Sysoev <igor@sysoev.ru>
parents:
2080
diff
changeset
|
501 != NGX_OK) |
2072 | 502 { |
2087
c8039b26a949
always test root existence for access_log with variables
Igor Sysoev <igor@sysoev.ru>
parents:
2080
diff
changeset
|
503 if (of.err == 0) { |
4499
778ef9c3fd2d
Fixed spelling in single-line comments.
Ruslan Ermilov <ru@nginx.com>
parents:
4494
diff
changeset
|
504 /* simulate successful logging */ |
2087
c8039b26a949
always test root existence for access_log with variables
Igor Sysoev <igor@sysoev.ru>
parents:
2080
diff
changeset
|
505 return len; |
c8039b26a949
always test root existence for access_log with variables
Igor Sysoev <igor@sysoev.ru>
parents:
2080
diff
changeset
|
506 } |
c8039b26a949
always test root existence for access_log with variables
Igor Sysoev <igor@sysoev.ru>
parents:
2080
diff
changeset
|
507 |
c8039b26a949
always test root existence for access_log with variables
Igor Sysoev <igor@sysoev.ru>
parents:
2080
diff
changeset
|
508 ngx_log_error(NGX_LOG_ERR, r->connection->log, of.err, |
c8039b26a949
always test root existence for access_log with variables
Igor Sysoev <igor@sysoev.ru>
parents:
2080
diff
changeset
|
509 "testing \"%s\" existence failed", path.data); |
c8039b26a949
always test root existence for access_log with variables
Igor Sysoev <igor@sysoev.ru>
parents:
2080
diff
changeset
|
510 |
4499
778ef9c3fd2d
Fixed spelling in single-line comments.
Ruslan Ermilov <ru@nginx.com>
parents:
4494
diff
changeset
|
511 /* simulate successful logging */ |
2087
c8039b26a949
always test root existence for access_log with variables
Igor Sysoev <igor@sysoev.ru>
parents:
2080
diff
changeset
|
512 return len; |
c8039b26a949
always test root existence for access_log with variables
Igor Sysoev <igor@sysoev.ru>
parents:
2080
diff
changeset
|
513 } |
c8039b26a949
always test root existence for access_log with variables
Igor Sysoev <igor@sysoev.ru>
parents:
2080
diff
changeset
|
514 |
c8039b26a949
always test root existence for access_log with variables
Igor Sysoev <igor@sysoev.ru>
parents:
2080
diff
changeset
|
515 if (!of.is_dir) { |
c8039b26a949
always test root existence for access_log with variables
Igor Sysoev <igor@sysoev.ru>
parents:
2080
diff
changeset
|
516 ngx_log_error(NGX_LOG_ERR, r->connection->log, NGX_ENOTDIR, |
c8039b26a949
always test root existence for access_log with variables
Igor Sysoev <igor@sysoev.ru>
parents:
2080
diff
changeset
|
517 "testing \"%s\" existence failed", path.data); |
c8039b26a949
always test root existence for access_log with variables
Igor Sysoev <igor@sysoev.ru>
parents:
2080
diff
changeset
|
518 |
4499
778ef9c3fd2d
Fixed spelling in single-line comments.
Ruslan Ermilov <ru@nginx.com>
parents:
4494
diff
changeset
|
519 /* simulate successful logging */ |
2072 | 520 return len; |
521 } | |
522 } | |
523 | |
524 if (ngx_http_script_run(r, &log, script->lengths->elts, 1, | |
525 script->values->elts) | |
526 == NULL) | |
527 { | |
4499
778ef9c3fd2d
Fixed spelling in single-line comments.
Ruslan Ermilov <ru@nginx.com>
parents:
4494
diff
changeset
|
528 /* simulate successful logging */ |
2072 | 529 return len; |
530 } | |
531 | |
532 log.data[log.len - 1] = '\0'; | |
533 *name = log.data; | |
534 | |
535 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
536 "http log \"%s\"", log.data); | |
537 | |
538 llcf = ngx_http_get_module_loc_conf(r, ngx_http_log_module); | |
539 | |
540 ngx_memzero(&of, sizeof(ngx_open_file_info_t)); | |
541 | |
542 of.log = 1; | |
543 of.valid = llcf->open_file_cache_valid; | |
544 of.min_uses = llcf->open_file_cache_min_uses; | |
2277 | 545 of.directio = NGX_OPEN_FILE_DIRECTIO_OFF; |
4494
13e09cf11d4e
Disable symlinks: initialization of the "disable_symlinks" field in
Valentin Bartenev <vbart@nginx.com>
parents:
4478
diff
changeset
|
546 |
13e09cf11d4e
Disable symlinks: initialization of the "disable_symlinks" field in
Valentin Bartenev <vbart@nginx.com>
parents:
4478
diff
changeset
|
547 if (ngx_http_set_disable_symlinks(r, clcf, &log, &of) != NGX_OK) { |
13e09cf11d4e
Disable symlinks: initialization of the "disable_symlinks" field in
Valentin Bartenev <vbart@nginx.com>
parents:
4478
diff
changeset
|
548 /* simulate successful logging */ |
13e09cf11d4e
Disable symlinks: initialization of the "disable_symlinks" field in
Valentin Bartenev <vbart@nginx.com>
parents:
4478
diff
changeset
|
549 return len; |
13e09cf11d4e
Disable symlinks: initialization of the "disable_symlinks" field in
Valentin Bartenev <vbart@nginx.com>
parents:
4478
diff
changeset
|
550 } |
2072 | 551 |
552 if (ngx_open_cached_file(llcf->open_file_cache, &log, &of, r->pool) | |
553 != NGX_OK) | |
554 { | |
555 ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno, | |
2756
09cab3f8d92e
*) of.test_only to not open file if only stat() is enough
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
556 "%s \"%s\" failed", of.failed, log.data); |
4499
778ef9c3fd2d
Fixed spelling in single-line comments.
Ruslan Ermilov <ru@nginx.com>
parents:
4494
diff
changeset
|
557 /* simulate successful logging */ |
2077 | 558 return len; |
2072 | 559 } |
560 | |
561 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
562 "http log #%d", of.fd); | |
563 | |
564 n = ngx_write_fd(of.fd, buf, len); | |
565 | |
566 return n; | |
567 } | |
568 | |
569 | |
4988
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
570 #if (NGX_ZLIB) |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
571 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
572 static ssize_t |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
573 ngx_http_log_gzip(ngx_fd_t fd, u_char *buf, size_t len, ngx_int_t level, |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
574 ngx_log_t *log) |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
575 { |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
576 int rc, wbits, memlevel; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
577 u_char *out; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
578 size_t size; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
579 ssize_t n; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
580 z_stream zstream; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
581 ngx_err_t err; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
582 ngx_pool_t *pool; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
583 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
584 wbits = MAX_WBITS; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
585 memlevel = MAX_MEM_LEVEL - 1; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
586 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
587 while ((ssize_t) len < ((1 << (wbits - 1)) - 262)) { |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
588 wbits--; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
589 memlevel--; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
590 } |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
591 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
592 /* |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
593 * This is a formula from deflateBound() for conservative upper bound of |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
594 * compressed data plus 18 bytes of gzip wrapper. |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
595 */ |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
596 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
597 size = len + ((len + 7) >> 3) + ((len + 63) >> 6) + 5 + 18; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
598 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
599 ngx_memzero(&zstream, sizeof(z_stream)); |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
600 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
601 pool = ngx_create_pool(256, log); |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
602 if (pool == NULL) { |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
603 /* simulate successful logging */ |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
604 return len; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
605 } |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
606 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
607 pool->log = log; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
608 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
609 zstream.zalloc = ngx_http_log_gzip_alloc; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
610 zstream.zfree = ngx_http_log_gzip_free; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
611 zstream.opaque = pool; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
612 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
613 out = ngx_pnalloc(pool, size); |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
614 if (out == NULL) { |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
615 goto done; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
616 } |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
617 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
618 zstream.next_in = buf; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
619 zstream.avail_in = len; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
620 zstream.next_out = out; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
621 zstream.avail_out = size; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
622 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
623 rc = deflateInit2(&zstream, (int) level, Z_DEFLATED, wbits + 16, memlevel, |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
624 Z_DEFAULT_STRATEGY); |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
625 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
626 if (rc != Z_OK) { |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
627 ngx_log_error(NGX_LOG_ALERT, log, 0, "deflateInit2() failed: %d", rc); |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
628 goto done; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
629 } |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
630 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
631 ngx_log_debug4(NGX_LOG_DEBUG_HTTP, log, 0, |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
632 "deflate in: ni:%p no:%p ai:%ud ao:%ud", |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
633 zstream.next_in, zstream.next_out, |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
634 zstream.avail_in, zstream.avail_out); |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
635 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
636 rc = deflate(&zstream, Z_FINISH); |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
637 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
638 if (rc != Z_STREAM_END) { |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
639 ngx_log_error(NGX_LOG_ALERT, log, 0, |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
640 "deflate(Z_FINISH) failed: %d", rc); |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
641 goto done; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
642 } |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
643 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
644 ngx_log_debug5(NGX_LOG_DEBUG_HTTP, log, 0, |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
645 "deflate out: ni:%p no:%p ai:%ud ao:%ud rc:%d", |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
646 zstream.next_in, zstream.next_out, |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
647 zstream.avail_in, zstream.avail_out, |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
648 rc); |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
649 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
650 size -= zstream.avail_out; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
651 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
652 rc = deflateEnd(&zstream); |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
653 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
654 if (rc != Z_OK) { |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
655 ngx_log_error(NGX_LOG_ALERT, log, 0, "deflateEnd() failed: %d", rc); |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
656 goto done; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
657 } |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
658 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
659 n = ngx_write_fd(fd, out, size); |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
660 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
661 if (n != (ssize_t) size) { |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
662 err = (n == -1) ? ngx_errno : 0; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
663 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
664 ngx_destroy_pool(pool); |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
665 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
666 ngx_set_errno(err); |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
667 return -1; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
668 } |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
669 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
670 done: |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
671 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
672 ngx_destroy_pool(pool); |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
673 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
674 /* simulate successful logging */ |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
675 return len; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
676 } |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
677 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
678 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
679 static void * |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
680 ngx_http_log_gzip_alloc(void *opaque, u_int items, u_int size) |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
681 { |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
682 ngx_pool_t *pool = opaque; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
683 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
684 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, pool->log, 0, |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
685 "gzip alloc: n:%ud s:%ud", items, size); |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
686 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
687 return ngx_palloc(pool, items * size); |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
688 } |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
689 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
690 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
691 static void |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
692 ngx_http_log_gzip_free(void *opaque, void *address) |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
693 { |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
694 #if 0 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
695 ngx_pool_t *pool = opaque; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
696 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
697 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pool->log, 0, "gzip free: %p", address); |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
698 #endif |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
699 } |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
700 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
701 #endif |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
702 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
703 |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
704 static void |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
705 ngx_http_log_flush(ngx_open_file_t *file, ngx_log_t *log) |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
706 { |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
707 size_t len; |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
708 ssize_t n; |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
709 ngx_http_log_buf_t *buffer; |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
710 |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
711 buffer = file->data; |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
712 |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
713 len = buffer->pos - buffer->start; |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
714 |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
715 if (len == 0) { |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
716 return; |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
717 } |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
718 |
4988
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
719 #if (NGX_ZLIB) |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
720 if (buffer->gzip) { |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
721 n = ngx_http_log_gzip(file->fd, buffer->start, len, buffer->gzip, log); |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
722 } else { |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
723 n = ngx_write_fd(file->fd, buffer->start, len); |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
724 } |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
725 #else |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
726 n = ngx_write_fd(file->fd, buffer->start, len); |
4988
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
727 #endif |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
728 |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
729 if (n == -1) { |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
730 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
731 ngx_write_fd_n " to \"%s\" failed", |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
732 file->name.data); |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
733 |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
734 } else if ((size_t) n != len) { |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
735 ngx_log_error(NGX_LOG_ALERT, log, 0, |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
736 ngx_write_fd_n " to \"%s\" was incomplete: %z of %uz", |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
737 file->name.data, n, len); |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
738 } |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
739 |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
740 buffer->pos = buffer->start; |
4986
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
741 |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
742 if (buffer->event && buffer->event->timer_set) { |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
743 ngx_del_timer(buffer->event); |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
744 } |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
745 } |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
746 |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
747 |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
748 static void |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
749 ngx_http_log_flush_handler(ngx_event_t *ev) |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
750 { |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
751 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, ev->log, 0, |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
752 "http log buffer flush handler"); |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
753 |
6927
c36d160cd4e0
Access log: removed dead ev->timedout check in flush timer handler.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6840
diff
changeset
|
754 ngx_http_log_flush(ev->data, ev->log); |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
755 } |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
756 |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
757 |
497 | 758 static u_char * |
759 ngx_http_log_copy_short(ngx_http_request_t *r, u_char *buf, | |
760 ngx_http_log_op_t *op) | |
479 | 761 { |
762 size_t len; | |
763 uintptr_t data; | |
764 | |
765 len = op->len; | |
766 data = op->data; | |
767 | |
768 while (len--) { | |
769 *buf++ = (u_char) (data & 0xff); | |
770 data >>= 8; | |
771 } | |
772 | |
773 return buf; | |
774 } | |
775 | |
776 | |
497 | 777 static u_char * |
778 ngx_http_log_copy_long(ngx_http_request_t *r, u_char *buf, | |
779 ngx_http_log_op_t *op) | |
479 | 780 { |
781 return ngx_cpymem(buf, (u_char *) op->data, op->len); | |
782 } | |
783 | |
784 | |
497 | 785 static u_char * |
786 ngx_http_log_pipe(ngx_http_request_t *r, u_char *buf, ngx_http_log_op_t *op) | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
787 { |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
788 if (r->pipeline) { |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
789 *buf = 'p'; |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
790 } else { |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
791 *buf = '.'; |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
792 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
793 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
794 return buf + 1; |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
795 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
796 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
797 |
497 | 798 static u_char * |
799 ngx_http_log_time(ngx_http_request_t *r, u_char *buf, ngx_http_log_op_t *op) | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
800 { |
178
a8ff48d26cca
nginx-0.0.1-2003-11-11-00:09:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
177
diff
changeset
|
801 return ngx_cpymem(buf, ngx_cached_http_log_time.data, |
a8ff48d26cca
nginx-0.0.1-2003-11-11-00:09:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
177
diff
changeset
|
802 ngx_cached_http_log_time.len); |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
803 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
804 |
3873 | 805 static u_char * |
806 ngx_http_log_iso8601(ngx_http_request_t *r, u_char *buf, ngx_http_log_op_t *op) | |
807 { | |
808 return ngx_cpymem(buf, ngx_cached_http_log_iso8601.data, | |
809 ngx_cached_http_log_iso8601.len); | |
810 } | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
811 |
497 | 812 static u_char * |
813 ngx_http_log_msec(ngx_http_request_t *r, u_char *buf, ngx_http_log_op_t *op) | |
409
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
393
diff
changeset
|
814 { |
563 | 815 ngx_time_t *tp; |
409
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
393
diff
changeset
|
816 |
563 | 817 tp = ngx_timeofday(); |
409
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
393
diff
changeset
|
818 |
563 | 819 return ngx_sprintf(buf, "%T.%03M", tp->sec, tp->msec); |
409
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
393
diff
changeset
|
820 } |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
393
diff
changeset
|
821 |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
393
diff
changeset
|
822 |
497 | 823 static u_char * |
824 ngx_http_log_request_time(ngx_http_request_t *r, u_char *buf, | |
825 ngx_http_log_op_t *op) | |
826 { | |
1179
6e2216ad2c87
$request_time has millisecond precision
Igor Sysoev <igor@sysoev.ru>
parents:
1161
diff
changeset
|
827 ngx_time_t *tp; |
6e2216ad2c87
$request_time has millisecond precision
Igor Sysoev <igor@sysoev.ru>
parents:
1161
diff
changeset
|
828 ngx_msec_int_t ms; |
6e2216ad2c87
$request_time has millisecond precision
Igor Sysoev <igor@sysoev.ru>
parents:
1161
diff
changeset
|
829 |
6e2216ad2c87
$request_time has millisecond precision
Igor Sysoev <igor@sysoev.ru>
parents:
1161
diff
changeset
|
830 tp = ngx_timeofday(); |
497 | 831 |
1640 | 832 ms = (ngx_msec_int_t) |
833 ((tp->sec - r->start_sec) * 1000 + (tp->msec - r->start_msec)); | |
3515 | 834 ms = ngx_max(ms, 0); |
497 | 835 |
5361
7094d6da2806
Win32: $request_time fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5330
diff
changeset
|
836 return ngx_sprintf(buf, "%T.%03M", (time_t) ms / 1000, ms % 1000); |
497 | 837 } |
838 | |
839 | |
840 static u_char * | |
841 ngx_http_log_status(ngx_http_request_t *r, u_char *buf, ngx_http_log_op_t *op) | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
842 { |
3370
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
843 ngx_uint_t status; |
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
844 |
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
845 if (r->err_status) { |
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
846 status = r->err_status; |
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
847 |
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
848 } else if (r->headers_out.status) { |
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
849 status = r->headers_out.status; |
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
850 |
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
851 } else if (r->http_version == NGX_HTTP_VERSION_9) { |
4685
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4637
diff
changeset
|
852 status = 9; |
3370
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
853 |
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
854 } else { |
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
855 status = 0; |
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
856 } |
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
857 |
4637
668ab1a21327
Zero padded the returned and logged HTTP status code, and fixed possible
Ruslan Ermilov <ru@nginx.com>
parents:
4539
diff
changeset
|
858 return ngx_sprintf(buf, "%03ui", status); |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
859 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
860 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
861 |
497 | 862 static u_char * |
573 | 863 ngx_http_log_bytes_sent(ngx_http_request_t *r, u_char *buf, |
864 ngx_http_log_op_t *op) | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
865 { |
455 | 866 return ngx_sprintf(buf, "%O", r->connection->sent); |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
867 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
868 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
869 |
1271 | 870 /* |
871 * although there is a real $body_bytes_sent variable, | |
872 * this log operation code function is more optimized for logging | |
873 */ | |
874 | |
497 | 875 static u_char * |
577 | 876 ngx_http_log_body_bytes_sent(ngx_http_request_t *r, u_char *buf, |
497 | 877 ngx_http_log_op_t *op) |
210
00cafae0bdf1
nginx-0.0.1-2003-12-14-23:10:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
878 { |
497 | 879 off_t length; |
880 | |
881 length = r->connection->sent - r->header_size; | |
882 | |
883 if (length > 0) { | |
884 return ngx_sprintf(buf, "%O", length); | |
885 } | |
886 | |
887 *buf = '0'; | |
888 | |
889 return buf + 1; | |
210
00cafae0bdf1
nginx-0.0.1-2003-12-14-23:10:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
890 } |
00cafae0bdf1
nginx-0.0.1-2003-12-14-23:10:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
891 |
00cafae0bdf1
nginx-0.0.1-2003-12-14-23:10:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
892 |
497 | 893 static u_char * |
894 ngx_http_log_request_length(ngx_http_request_t *r, u_char *buf, | |
895 ngx_http_log_op_t *op) | |
475 | 896 { |
663 | 897 return ngx_sprintf(buf, "%O", r->request_length); |
475 | 898 } |
899 | |
900 | |
497 | 901 static ngx_int_t |
501 | 902 ngx_http_log_variable_compile(ngx_conf_t *cf, ngx_http_log_op_t *op, |
6840
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
903 ngx_str_t *value, ngx_uint_t json) |
501 | 904 { |
509 | 905 ngx_int_t index; |
501 | 906 |
509 | 907 index = ngx_http_get_variable_index(cf, value); |
908 if (index == NGX_ERROR) { | |
501 | 909 return NGX_ERROR; |
910 } | |
911 | |
912 op->len = 0; | |
6840
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
913 |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
914 if (json) { |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
915 op->getlen = ngx_http_log_json_variable_getlen; |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
916 op->run = ngx_http_log_json_variable; |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
917 |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
918 } else { |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
919 op->getlen = ngx_http_log_variable_getlen; |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
920 op->run = ngx_http_log_variable; |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
921 } |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
922 |
509 | 923 op->data = index; |
501 | 924 |
925 return NGX_OK; | |
926 } | |
927 | |
928 | |
929 static size_t | |
930 ngx_http_log_variable_getlen(ngx_http_request_t *r, uintptr_t data) | |
931 { | |
2008
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
932 uintptr_t len; |
501 | 933 ngx_http_variable_value_t *value; |
934 | |
935 value = ngx_http_get_indexed_variable(r, data); | |
936 | |
573 | 937 if (value == NULL || value->not_found) { |
501 | 938 return 1; |
939 } | |
940 | |
2008
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
941 len = ngx_http_log_escape(NULL, value->data, value->len); |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
942 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
943 value->escape = len ? 1 : 0; |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
944 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
945 return value->len + len * 3; |
501 | 946 } |
947 | |
948 | |
949 static u_char * | |
950 ngx_http_log_variable(ngx_http_request_t *r, u_char *buf, ngx_http_log_op_t *op) | |
951 { | |
952 ngx_http_variable_value_t *value; | |
953 | |
954 value = ngx_http_get_indexed_variable(r, op->data); | |
955 | |
573 | 956 if (value == NULL || value->not_found) { |
501 | 957 *buf = '-'; |
958 return buf + 1; | |
959 } | |
960 | |
2008
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
961 if (value->escape == 0) { |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
962 return ngx_cpymem(buf, value->data, value->len); |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
963 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
964 } else { |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
965 return (u_char *) ngx_http_log_escape(buf, value->data, value->len); |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
966 } |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
967 } |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
968 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
969 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
970 static uintptr_t |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
971 ngx_http_log_escape(u_char *dst, u_char *src, size_t size) |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
972 { |
3275 | 973 ngx_uint_t n; |
2008
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
974 static u_char hex[] = "0123456789ABCDEF"; |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
975 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
976 static uint32_t escape[] = { |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
977 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
978 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
979 /* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */ |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
980 0x00000004, /* 0000 0000 0000 0000 0000 0000 0000 0100 */ |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
981 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
982 /* _^]\ [ZYX WVUT SRQP ONML KJIH GFED CBA@ */ |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
983 0x10000000, /* 0001 0000 0000 0000 0000 0000 0000 0000 */ |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
984 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
985 /* ~}| {zyx wvut srqp onml kjih gfed cba` */ |
4191
08d8af70760c
Improved access log escaping to better protect other software.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4133
diff
changeset
|
986 0x80000000, /* 1000 0000 0000 0000 0000 0000 0000 0000 */ |
2008
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
987 |
4191
08d8af70760c
Improved access log escaping to better protect other software.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4133
diff
changeset
|
988 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ |
08d8af70760c
Improved access log escaping to better protect other software.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4133
diff
changeset
|
989 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ |
08d8af70760c
Improved access log escaping to better protect other software.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4133
diff
changeset
|
990 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ |
08d8af70760c
Improved access log escaping to better protect other software.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4133
diff
changeset
|
991 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ |
2008
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
992 }; |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
993 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
994 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
995 if (dst == NULL) { |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
996 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
997 /* find the number of the characters to be escaped */ |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
998 |
3115 | 999 n = 0; |
2008
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
1000 |
3275 | 1001 while (size) { |
6626
b3682580c1bd
Avoid left-shifting integers into the sign bit, which is undefined.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5927
diff
changeset
|
1002 if (escape[*src >> 5] & (1U << (*src & 0x1f))) { |
2008
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
1003 n++; |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
1004 } |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
1005 src++; |
3275 | 1006 size--; |
2008
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
1007 } |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
1008 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
1009 return (uintptr_t) n; |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
1010 } |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
1011 |
3275 | 1012 while (size) { |
6626
b3682580c1bd
Avoid left-shifting integers into the sign bit, which is undefined.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5927
diff
changeset
|
1013 if (escape[*src >> 5] & (1U << (*src & 0x1f))) { |
2008
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
1014 *dst++ = '\\'; |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
1015 *dst++ = 'x'; |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
1016 *dst++ = hex[*src >> 4]; |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
1017 *dst++ = hex[*src & 0xf]; |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
1018 src++; |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
1019 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
1020 } else { |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
1021 *dst++ = *src++; |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
1022 } |
3275 | 1023 size--; |
2008
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
1024 } |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
1025 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
1026 return (uintptr_t) dst; |
501 | 1027 } |
1028 | |
1029 | |
6840
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1030 static size_t |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1031 ngx_http_log_json_variable_getlen(ngx_http_request_t *r, uintptr_t data) |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1032 { |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1033 uintptr_t len; |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1034 ngx_http_variable_value_t *value; |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1035 |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1036 value = ngx_http_get_indexed_variable(r, data); |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1037 |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1038 if (value == NULL || value->not_found) { |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1039 return 0; |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1040 } |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1041 |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1042 len = ngx_escape_json(NULL, value->data, value->len); |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1043 |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1044 value->escape = len ? 1 : 0; |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1045 |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1046 return value->len + len; |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1047 } |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1048 |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1049 |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1050 static u_char * |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1051 ngx_http_log_json_variable(ngx_http_request_t *r, u_char *buf, |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1052 ngx_http_log_op_t *op) |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1053 { |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1054 ngx_http_variable_value_t *value; |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1055 |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1056 value = ngx_http_get_indexed_variable(r, op->data); |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1057 |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1058 if (value == NULL || value->not_found) { |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1059 return buf; |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1060 } |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1061 |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1062 if (value->escape == 0) { |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1063 return ngx_cpymem(buf, value->data, value->len); |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1064 |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1065 } else { |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1066 return (u_char *) ngx_escape_json(buf, value->data, value->len); |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1067 } |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1068 } |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1069 |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1070 |
497 | 1071 static void * |
1072 ngx_http_log_create_main_conf(ngx_conf_t *cf) | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1073 { |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1074 ngx_http_log_main_conf_t *conf; |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1075 |
573 | 1076 ngx_http_log_fmt_t *fmt; |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1077 |
501 | 1078 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_log_main_conf_t)); |
1079 if (conf == NULL) { | |
2912
c7d57b539248
return NULL instead of NGX_CONF_ERROR on a create conf failure
Igor Sysoev <igor@sysoev.ru>
parents:
2756
diff
changeset
|
1080 return NULL; |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1081 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1082 |
497 | 1083 if (ngx_array_init(&conf->formats, cf->pool, 4, sizeof(ngx_http_log_fmt_t)) |
573 | 1084 != NGX_OK) |
497 | 1085 { |
2912
c7d57b539248
return NULL instead of NGX_CONF_ERROR on a create conf failure
Igor Sysoev <igor@sysoev.ru>
parents:
2756
diff
changeset
|
1086 return NULL; |
497 | 1087 } |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1088 |
573 | 1089 fmt = ngx_array_push(&conf->formats); |
1090 if (fmt == NULL) { | |
2912
c7d57b539248
return NULL instead of NGX_CONF_ERROR on a create conf failure
Igor Sysoev <igor@sysoev.ru>
parents:
2756
diff
changeset
|
1091 return NULL; |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1092 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1093 |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1094 ngx_str_set(&fmt->name, "combined"); |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1095 |
2261 | 1096 fmt->flushes = NULL; |
1097 | |
573 | 1098 fmt->ops = ngx_array_create(cf->pool, 16, sizeof(ngx_http_log_op_t)); |
1099 if (fmt->ops == NULL) { | |
2912
c7d57b539248
return NULL instead of NGX_CONF_ERROR on a create conf failure
Igor Sysoev <igor@sysoev.ru>
parents:
2756
diff
changeset
|
1100 return NULL; |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1101 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1102 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1103 return conf; |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1104 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1105 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1106 |
497 | 1107 static void * |
1108 ngx_http_log_create_loc_conf(ngx_conf_t *cf) | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1109 { |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1110 ngx_http_log_loc_conf_t *conf; |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1111 |
501 | 1112 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_log_loc_conf_t)); |
1113 if (conf == NULL) { | |
2912
c7d57b539248
return NULL instead of NGX_CONF_ERROR on a create conf failure
Igor Sysoev <igor@sysoev.ru>
parents:
2756
diff
changeset
|
1114 return NULL; |
427
0d08eabe5c7b
nginx-0.0.10-2004-09-15-20:00:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
1115 } |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
1116 |
2072 | 1117 conf->open_file_cache = NGX_CONF_UNSET_PTR; |
1118 | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
1119 return conf; |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
1120 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
1121 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
1122 |
497 | 1123 static char * |
1124 ngx_http_log_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child) | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
1125 { |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1126 ngx_http_log_loc_conf_t *prev = parent; |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1127 ngx_http_log_loc_conf_t *conf = child; |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1128 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1129 ngx_http_log_t *log; |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1130 ngx_http_log_fmt_t *fmt; |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1131 ngx_http_log_main_conf_t *lmcf; |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1132 |
2072 | 1133 if (conf->open_file_cache == NGX_CONF_UNSET_PTR) { |
1134 | |
1135 conf->open_file_cache = prev->open_file_cache; | |
1136 conf->open_file_cache_valid = prev->open_file_cache_valid; | |
1137 conf->open_file_cache_min_uses = prev->open_file_cache_min_uses; | |
1138 | |
1139 if (conf->open_file_cache == NGX_CONF_UNSET_PTR) { | |
1140 conf->open_file_cache = NULL; | |
1141 } | |
1142 } | |
1143 | |
1074 | 1144 if (conf->logs || conf->off) { |
1145 return NGX_CONF_OK; | |
1146 } | |
427
0d08eabe5c7b
nginx-0.0.10-2004-09-15-20:00:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
1147 |
2078
9acbc5e7bcbd
fix variable access_log merging
Igor Sysoev <igor@sysoev.ru>
parents:
2077
diff
changeset
|
1148 conf->logs = prev->logs; |
9acbc5e7bcbd
fix variable access_log merging
Igor Sysoev <igor@sysoev.ru>
parents:
2077
diff
changeset
|
1149 conf->off = prev->off; |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1150 |
1074 | 1151 if (conf->logs || conf->off) { |
1152 return NGX_CONF_OK; | |
1153 } | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
1154 |
1074 | 1155 conf->logs = ngx_array_create(cf->pool, 2, sizeof(ngx_http_log_t)); |
1156 if (conf->logs == NULL) { | |
1157 return NGX_CONF_ERROR; | |
1158 } | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1159 |
1074 | 1160 log = ngx_array_push(conf->logs); |
1161 if (log == NULL) { | |
1162 return NGX_CONF_ERROR; | |
1163 } | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1164 |
5719
7f425d67f91a
Access log: fix default value, broken by cb308813b453.
Piotr Sikora <piotr@cloudflare.com>
parents:
5702
diff
changeset
|
1165 ngx_memzero(log, sizeof(ngx_http_log_t)); |
7f425d67f91a
Access log: fix default value, broken by cb308813b453.
Piotr Sikora <piotr@cloudflare.com>
parents:
5702
diff
changeset
|
1166 |
1074 | 1167 log->file = ngx_conf_open_file(cf->cycle, &ngx_http_access_log); |
1168 if (log->file == NULL) { | |
1169 return NGX_CONF_ERROR; | |
1170 } | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1171 |
1074 | 1172 lmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_log_module); |
1173 fmt = lmcf->formats.elts; | |
1174 | |
1175 /* the default "combined" format */ | |
2261 | 1176 log->format = &fmt[0]; |
1074 | 1177 lmcf->combined_used = 1; |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
1178 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
1179 return NGX_CONF_OK; |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
1180 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
1181 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
1182 |
497 | 1183 static char * |
1184 ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
1185 { |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1186 ngx_http_log_loc_conf_t *llcf = conf; |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
1187 |
5653
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
1188 ssize_t size; |
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
1189 ngx_int_t gzip; |
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
1190 ngx_uint_t i, n; |
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
1191 ngx_msec_t flush; |
5833
e3016ee8dba3
Access log: fixed the "if=" parameter with buffering (ticket #625).
Valentin Bartenev <vbart@nginx.com>
parents:
5799
diff
changeset
|
1192 ngx_str_t *value, name, s; |
5653
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
1193 ngx_http_log_t *log; |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
1194 ngx_syslog_peer_t *peer; |
5653
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
1195 ngx_http_log_buf_t *buffer; |
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
1196 ngx_http_log_fmt_t *fmt; |
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
1197 ngx_http_log_main_conf_t *lmcf; |
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
1198 ngx_http_script_compile_t sc; |
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
1199 ngx_http_compile_complex_value_t ccv; |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1200 |
427
0d08eabe5c7b
nginx-0.0.10-2004-09-15-20:00:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
1201 value = cf->args->elts; |
0d08eabe5c7b
nginx-0.0.10-2004-09-15-20:00:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
1202 |
0d08eabe5c7b
nginx-0.0.10-2004-09-15-20:00:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
1203 if (ngx_strcmp(value[1].data, "off") == 0) { |
0d08eabe5c7b
nginx-0.0.10-2004-09-15-20:00:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
1204 llcf->off = 1; |
3038
cd8738e76610
strict testing "access_log off"
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
1205 if (cf->args->nelts == 2) { |
cd8738e76610
strict testing "access_log off"
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
1206 return NGX_CONF_OK; |
cd8738e76610
strict testing "access_log off"
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
1207 } |
cd8738e76610
strict testing "access_log off"
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
1208 |
cd8738e76610
strict testing "access_log off"
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
1209 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
cd8738e76610
strict testing "access_log off"
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
1210 "invalid parameter \"%V\"", &value[2]); |
cd8738e76610
strict testing "access_log off"
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
1211 return NGX_CONF_ERROR; |
427
0d08eabe5c7b
nginx-0.0.10-2004-09-15-20:00:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
1212 } |
0d08eabe5c7b
nginx-0.0.10-2004-09-15-20:00:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
1213 |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1214 if (llcf->logs == NULL) { |
427
0d08eabe5c7b
nginx-0.0.10-2004-09-15-20:00:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
1215 llcf->logs = ngx_array_create(cf->pool, 2, sizeof(ngx_http_log_t)); |
0d08eabe5c7b
nginx-0.0.10-2004-09-15-20:00:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
1216 if (llcf->logs == NULL) { |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1217 return NGX_CONF_ERROR; |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1218 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1219 } |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
1220 |
393
5659d773cfa8
nginx-0.0.7-2004-07-15-20:35:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
356
diff
changeset
|
1221 lmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_log_module); |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
1222 |
501 | 1223 log = ngx_array_push(llcf->logs); |
1224 if (log == NULL) { | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1225 return NGX_CONF_ERROR; |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1226 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1227 |
2072 | 1228 ngx_memzero(log, sizeof(ngx_http_log_t)); |
1229 | |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
1230 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
1231 if (ngx_strncmp(value[1].data, "syslog:", 7) == 0) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
1232 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
1233 peer = ngx_pcalloc(cf->pool, sizeof(ngx_syslog_peer_t)); |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
1234 if (peer == NULL) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
1235 return NGX_CONF_ERROR; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
1236 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
1237 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
1238 if (ngx_syslog_process_conf(cf, peer) != NGX_CONF_OK) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
1239 return NGX_CONF_ERROR; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
1240 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
1241 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
1242 log->syslog_peer = peer; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
1243 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
1244 goto process_formats; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
1245 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
1246 |
2072 | 1247 n = ngx_http_script_variables_count(&value[1]); |
1248 | |
1249 if (n == 0) { | |
1250 log->file = ngx_conf_open_file(cf->cycle, &value[1]); | |
1251 if (log->file == NULL) { | |
1252 return NGX_CONF_ERROR; | |
1253 } | |
1254 | |
1255 } else { | |
5330
314c3d7cc3a5
Backed out f1a91825730a and 7094bd12c1ff.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5317
diff
changeset
|
1256 if (ngx_conf_full_name(cf->cycle, &value[1], 0) != NGX_OK) { |
2072 | 1257 return NGX_CONF_ERROR; |
1258 } | |
1259 | |
1260 log->script = ngx_pcalloc(cf->pool, sizeof(ngx_http_log_script_t)); | |
1261 if (log->script == NULL) { | |
1262 return NGX_CONF_ERROR; | |
1263 } | |
1264 | |
1265 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t)); | |
1266 | |
1267 sc.cf = cf; | |
1268 sc.source = &value[1]; | |
1269 sc.lengths = &log->script->lengths; | |
1270 sc.values = &log->script->values; | |
1271 sc.variables = n; | |
1272 sc.complete_lengths = 1; | |
1273 sc.complete_values = 1; | |
1274 | |
1275 if (ngx_http_script_compile(&sc) != NGX_OK) { | |
1276 return NGX_CONF_ERROR; | |
1277 } | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1278 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1279 |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
1280 process_formats: |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
1281 |
571 | 1282 if (cf->args->nelts >= 3) { |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1283 name = value[2]; |
581 | 1284 |
1285 if (ngx_strcmp(name.data, "combined") == 0) { | |
1286 lmcf->combined_used = 1; | |
1287 } | |
1288 | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1289 } else { |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1290 ngx_str_set(&name, "combined"); |
573 | 1291 lmcf->combined_used = 1; |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1292 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1293 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1294 fmt = lmcf->formats.elts; |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1295 for (i = 0; i < lmcf->formats.nelts; i++) { |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1296 if (fmt[i].name.len == name.len |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1297 && ngx_strcasecmp(fmt[i].name.data, name.data) == 0) |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1298 { |
2261 | 1299 log->format = &fmt[i]; |
4986
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1300 break; |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1301 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1302 } |
100
7ebc8b7fb816
nginx-0.0.1-2003-06-03-19:42:58 import
Igor Sysoev <igor@sysoev.ru>
parents:
99
diff
changeset
|
1303 |
4986
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1304 if (log->format == NULL) { |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1305 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1306 "unknown log format \"%V\"", &name); |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1307 return NGX_CONF_ERROR; |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1308 } |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1309 |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1310 size = 0; |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1311 flush = 0; |
4988
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1312 gzip = 0; |
4986
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1313 |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1314 for (i = 3; i < cf->args->nelts; i++) { |
487 | 1315 |
4986
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1316 if (ngx_strncmp(value[i].data, "buffer=", 7) == 0) { |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1317 s.len = value[i].len - 7; |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1318 s.data = value[i].data + 7; |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1319 |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1320 size = ngx_parse_size(&s); |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1321 |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1322 if (size == NGX_ERROR || size == 0) { |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1323 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1324 "invalid buffer size \"%V\"", &s); |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1325 return NGX_CONF_ERROR; |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1326 } |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1327 |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1328 continue; |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1329 } |
571 | 1330 |
4986
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1331 if (ngx_strncmp(value[i].data, "flush=", 6) == 0) { |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1332 s.len = value[i].len - 6; |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1333 s.data = value[i].data + 6; |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1334 |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1335 flush = ngx_parse_time(&s, 0); |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1336 |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1337 if (flush == (ngx_msec_t) NGX_ERROR || flush == 0) { |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1338 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1339 "invalid flush time \"%V\"", &s); |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1340 return NGX_CONF_ERROR; |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1341 } |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1342 |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1343 continue; |
571 | 1344 } |
1345 | |
4988
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1346 if (ngx_strncmp(value[i].data, "gzip", 4) == 0 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1347 && (value[i].len == 4 || value[i].data[4] == '=')) |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1348 { |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1349 #if (NGX_ZLIB) |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1350 if (size == 0) { |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1351 size = 64 * 1024; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1352 } |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1353 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1354 if (value[i].len == 4) { |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1355 gzip = Z_BEST_SPEED; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1356 continue; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1357 } |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1358 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1359 s.len = value[i].len - 5; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1360 s.data = value[i].data + 5; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1361 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1362 gzip = ngx_atoi(s.data, s.len); |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1363 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1364 if (gzip < 1 || gzip > 9) { |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1365 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1366 "invalid compression level \"%V\"", &s); |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1367 return NGX_CONF_ERROR; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1368 } |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1369 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1370 continue; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1371 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1372 #else |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1373 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1374 "nginx was built without zlib support"); |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1375 return NGX_CONF_ERROR; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1376 #endif |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1377 } |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1378 |
5653
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
1379 if (ngx_strncmp(value[i].data, "if=", 3) == 0) { |
5833
e3016ee8dba3
Access log: fixed the "if=" parameter with buffering (ticket #625).
Valentin Bartenev <vbart@nginx.com>
parents:
5799
diff
changeset
|
1380 s.len = value[i].len - 3; |
e3016ee8dba3
Access log: fixed the "if=" parameter with buffering (ticket #625).
Valentin Bartenev <vbart@nginx.com>
parents:
5799
diff
changeset
|
1381 s.data = value[i].data + 3; |
e3016ee8dba3
Access log: fixed the "if=" parameter with buffering (ticket #625).
Valentin Bartenev <vbart@nginx.com>
parents:
5799
diff
changeset
|
1382 |
e3016ee8dba3
Access log: fixed the "if=" parameter with buffering (ticket #625).
Valentin Bartenev <vbart@nginx.com>
parents:
5799
diff
changeset
|
1383 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t)); |
e3016ee8dba3
Access log: fixed the "if=" parameter with buffering (ticket #625).
Valentin Bartenev <vbart@nginx.com>
parents:
5799
diff
changeset
|
1384 |
e3016ee8dba3
Access log: fixed the "if=" parameter with buffering (ticket #625).
Valentin Bartenev <vbart@nginx.com>
parents:
5799
diff
changeset
|
1385 ccv.cf = cf; |
e3016ee8dba3
Access log: fixed the "if=" parameter with buffering (ticket #625).
Valentin Bartenev <vbart@nginx.com>
parents:
5799
diff
changeset
|
1386 ccv.value = &s; |
e3016ee8dba3
Access log: fixed the "if=" parameter with buffering (ticket #625).
Valentin Bartenev <vbart@nginx.com>
parents:
5799
diff
changeset
|
1387 ccv.complex_value = ngx_palloc(cf->pool, |
e3016ee8dba3
Access log: fixed the "if=" parameter with buffering (ticket #625).
Valentin Bartenev <vbart@nginx.com>
parents:
5799
diff
changeset
|
1388 sizeof(ngx_http_complex_value_t)); |
e3016ee8dba3
Access log: fixed the "if=" parameter with buffering (ticket #625).
Valentin Bartenev <vbart@nginx.com>
parents:
5799
diff
changeset
|
1389 if (ccv.complex_value == NULL) { |
e3016ee8dba3
Access log: fixed the "if=" parameter with buffering (ticket #625).
Valentin Bartenev <vbart@nginx.com>
parents:
5799
diff
changeset
|
1390 return NGX_CONF_ERROR; |
e3016ee8dba3
Access log: fixed the "if=" parameter with buffering (ticket #625).
Valentin Bartenev <vbart@nginx.com>
parents:
5799
diff
changeset
|
1391 } |
e3016ee8dba3
Access log: fixed the "if=" parameter with buffering (ticket #625).
Valentin Bartenev <vbart@nginx.com>
parents:
5799
diff
changeset
|
1392 |
e3016ee8dba3
Access log: fixed the "if=" parameter with buffering (ticket #625).
Valentin Bartenev <vbart@nginx.com>
parents:
5799
diff
changeset
|
1393 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) { |
e3016ee8dba3
Access log: fixed the "if=" parameter with buffering (ticket #625).
Valentin Bartenev <vbart@nginx.com>
parents:
5799
diff
changeset
|
1394 return NGX_CONF_ERROR; |
e3016ee8dba3
Access log: fixed the "if=" parameter with buffering (ticket #625).
Valentin Bartenev <vbart@nginx.com>
parents:
5799
diff
changeset
|
1395 } |
e3016ee8dba3
Access log: fixed the "if=" parameter with buffering (ticket #625).
Valentin Bartenev <vbart@nginx.com>
parents:
5799
diff
changeset
|
1396 |
e3016ee8dba3
Access log: fixed the "if=" parameter with buffering (ticket #625).
Valentin Bartenev <vbart@nginx.com>
parents:
5799
diff
changeset
|
1397 log->filter = ccv.complex_value; |
e3016ee8dba3
Access log: fixed the "if=" parameter with buffering (ticket #625).
Valentin Bartenev <vbart@nginx.com>
parents:
5799
diff
changeset
|
1398 |
5653
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
1399 continue; |
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
1400 } |
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
1401 |
4986
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1402 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1403 "invalid parameter \"%V\"", &value[i]); |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1404 return NGX_CONF_ERROR; |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1405 } |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1406 |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1407 if (flush && size == 0) { |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1408 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1409 "no buffer is defined for access_log \"%V\"", |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1410 &value[1]); |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1411 return NGX_CONF_ERROR; |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1412 } |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1413 |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1414 if (size) { |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1415 |
2072 | 1416 if (log->script) { |
1417 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
4133
59b99f217c6d
Replaced "can not" with "cannot" and "could not" in a bunch of places.
Ruslan Ermilov <ru@nginx.com>
parents:
3991
diff
changeset
|
1418 "buffered logs cannot have variables in name"); |
2072 | 1419 return NGX_CONF_ERROR; |
1420 } | |
1421 | |
5799
b1f8285297a7
Access log: allowed logs to syslog with "if=" (ticket #596).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5719
diff
changeset
|
1422 if (log->syslog_peer) { |
b1f8285297a7
Access log: allowed logs to syslog with "if=" (ticket #596).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5719
diff
changeset
|
1423 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
b1f8285297a7
Access log: allowed logs to syslog with "if=" (ticket #596).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5719
diff
changeset
|
1424 "logs to syslog cannot be buffered"); |
b1f8285297a7
Access log: allowed logs to syslog with "if=" (ticket #596).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5719
diff
changeset
|
1425 return NGX_CONF_ERROR; |
b1f8285297a7
Access log: allowed logs to syslog with "if=" (ticket #596).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5719
diff
changeset
|
1426 } |
b1f8285297a7
Access log: allowed logs to syslog with "if=" (ticket #596).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5719
diff
changeset
|
1427 |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1428 if (log->file->data) { |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1429 buffer = log->file->data; |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1430 |
4986
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1431 if (buffer->last - buffer->start != size |
4988
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1432 || buffer->flush != flush |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1433 || buffer->gzip != gzip) |
4986
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1434 { |
4984
7737f0d788c1
Access log: fixed redundant buffer reallocation.
Valentin Bartenev <vbart@nginx.com>
parents:
4893
diff
changeset
|
1435 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
7737f0d788c1
Access log: fixed redundant buffer reallocation.
Valentin Bartenev <vbart@nginx.com>
parents:
4893
diff
changeset
|
1436 "access_log \"%V\" already defined " |
4986
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1437 "with conflicting parameters", |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1438 &value[1]); |
4984
7737f0d788c1
Access log: fixed redundant buffer reallocation.
Valentin Bartenev <vbart@nginx.com>
parents:
4893
diff
changeset
|
1439 return NGX_CONF_ERROR; |
7737f0d788c1
Access log: fixed redundant buffer reallocation.
Valentin Bartenev <vbart@nginx.com>
parents:
4893
diff
changeset
|
1440 } |
7737f0d788c1
Access log: fixed redundant buffer reallocation.
Valentin Bartenev <vbart@nginx.com>
parents:
4893
diff
changeset
|
1441 |
7737f0d788c1
Access log: fixed redundant buffer reallocation.
Valentin Bartenev <vbart@nginx.com>
parents:
4893
diff
changeset
|
1442 return NGX_CONF_OK; |
571 | 1443 } |
1444 | |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1445 buffer = ngx_pcalloc(cf->pool, sizeof(ngx_http_log_buf_t)); |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1446 if (buffer == NULL) { |
571 | 1447 return NGX_CONF_ERROR; |
1448 } | |
1449 | |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1450 buffer->start = ngx_pnalloc(cf->pool, size); |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1451 if (buffer->start == NULL) { |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1452 return NGX_CONF_ERROR; |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1453 } |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1454 |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1455 buffer->pos = buffer->start; |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1456 buffer->last = buffer->start + size; |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1457 |
4986
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1458 if (flush) { |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1459 buffer->event = ngx_pcalloc(cf->pool, sizeof(ngx_event_t)); |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1460 if (buffer->event == NULL) { |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1461 return NGX_CONF_ERROR; |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1462 } |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1463 |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1464 buffer->event->data = log->file; |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1465 buffer->event->handler = ngx_http_log_flush_handler; |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1466 buffer->event->log = &cf->cycle->new_log; |
5897
dff86e2246a5
Access log: cancel the flush timer on graceful shutdown.
Valentin Bartenev <vbart@nginx.com>
parents:
5833
diff
changeset
|
1467 buffer->event->cancelable = 1; |
4986
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1468 |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1469 buffer->flush = flush; |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1470 } |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1471 |
4988
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1472 buffer->gzip = gzip; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1473 |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1474 log->file->flush = ngx_http_log_flush; |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1475 log->file->data = buffer; |
571 | 1476 } |
1477 | |
1478 return NGX_CONF_OK; | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
1479 } |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1480 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1481 |
497 | 1482 static char * |
1483 ngx_http_log_set_format(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1484 { |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1485 ngx_http_log_main_conf_t *lmcf = conf; |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1486 |
573 | 1487 ngx_str_t *value; |
1488 ngx_uint_t i; | |
1489 ngx_http_log_fmt_t *fmt; | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1490 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1491 value = cf->args->elts; |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1492 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1493 fmt = lmcf->formats.elts; |
573 | 1494 for (i = 0; i < lmcf->formats.nelts; i++) { |
1495 if (fmt[i].name.len == value[1].len | |
1496 && ngx_strcmp(fmt[i].name.data, value[1].data) == 0) | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1497 { |
2036 | 1498 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
1499 "duplicate \"log_format\" name \"%V\"", | |
1500 &value[1]); | |
1501 return NGX_CONF_ERROR; | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1502 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1503 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1504 |
501 | 1505 fmt = ngx_array_push(&lmcf->formats); |
1506 if (fmt == NULL) { | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1507 return NGX_CONF_ERROR; |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1508 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1509 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1510 fmt->name = value[1]; |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1511 |
2261 | 1512 fmt->flushes = ngx_array_create(cf->pool, 4, sizeof(ngx_int_t)); |
1513 if (fmt->flushes == NULL) { | |
1514 return NGX_CONF_ERROR; | |
1515 } | |
1516 | |
573 | 1517 fmt->ops = ngx_array_create(cf->pool, 16, sizeof(ngx_http_log_op_t)); |
501 | 1518 if (fmt->ops == NULL) { |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1519 return NGX_CONF_ERROR; |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1520 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1521 |
2261 | 1522 return ngx_http_log_compile_format(cf, fmt->flushes, fmt->ops, cf->args, 2); |
573 | 1523 } |
1524 | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1525 |
573 | 1526 static char * |
2261 | 1527 ngx_http_log_compile_format(ngx_conf_t *cf, ngx_array_t *flushes, |
1528 ngx_array_t *ops, ngx_array_t *args, ngx_uint_t s) | |
573 | 1529 { |
880 | 1530 u_char *data, *p, ch; |
1531 size_t i, len; | |
1532 ngx_str_t *value, var; | |
2261 | 1533 ngx_int_t *flush; |
6840
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1534 ngx_uint_t bracket, json; |
880 | 1535 ngx_http_log_op_t *op; |
1536 ngx_http_log_var_t *v; | |
573 | 1537 |
6840
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1538 json = 0; |
573 | 1539 value = args->elts; |
1540 | |
6840
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1541 if (s < args->nelts && ngx_strncmp(value[s].data, "escape=", 7) == 0) { |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1542 data = value[s].data + 7; |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1543 |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1544 if (ngx_strcmp(data, "json") == 0) { |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1545 json = 1; |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1546 |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1547 } else if (ngx_strcmp(data, "default") != 0) { |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1548 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1549 "unknown log format escaping \"%s\"", data); |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1550 return NGX_CONF_ERROR; |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1551 } |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1552 |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1553 s++; |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1554 } |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1555 |
573 | 1556 for ( /* void */ ; s < args->nelts; s++) { |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1557 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1558 i = 0; |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1559 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1560 while (i < value[s].len) { |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1561 |
573 | 1562 op = ngx_array_push(ops); |
501 | 1563 if (op == NULL) { |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1564 return NGX_CONF_ERROR; |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1565 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1566 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1567 data = &value[s].data[i]; |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1568 |
880 | 1569 if (value[s].data[i] == '$') { |
569 | 1570 |
1571 if (++i == value[s].len) { | |
1572 goto invalid; | |
1573 } | |
1574 | |
1575 if (value[s].data[i] == '{') { | |
1576 bracket = 1; | |
1577 | |
1578 if (++i == value[s].len) { | |
1579 goto invalid; | |
1580 } | |
1581 | |
1582 var.data = &value[s].data[i]; | |
1583 | |
1584 } else { | |
1585 bracket = 0; | |
1586 var.data = &value[s].data[i]; | |
1587 } | |
1588 | |
1589 for (var.len = 0; i < value[s].len; i++, var.len++) { | |
1590 ch = value[s].data[i]; | |
1591 | |
1592 if (ch == '}' && bracket) { | |
1593 i++; | |
1594 bracket = 0; | |
1595 break; | |
1596 } | |
1597 | |
1598 if ((ch >= 'A' && ch <= 'Z') | |
1599 || (ch >= 'a' && ch <= 'z') | |
1600 || (ch >= '0' && ch <= '9') | |
1601 || ch == '_') | |
1602 { | |
1603 continue; | |
1604 } | |
1605 | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1606 break; |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1607 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1608 |
569 | 1609 if (bracket) { |
1610 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1611 "the closing bracket in \"%V\" " | |
1612 "variable is missing", &var); | |
1613 return NGX_CONF_ERROR; | |
1614 } | |
1615 | |
1616 if (var.len == 0) { | |
1617 goto invalid; | |
1618 } | |
1619 | |
573 | 1620 for (v = ngx_http_log_vars; v->name.len; v++) { |
1621 | |
1622 if (v->name.len == var.len | |
1623 && ngx_strncmp(v->name.data, var.data, var.len) == 0) | |
1624 { | |
1625 op->len = v->len; | |
1626 op->getlen = NULL; | |
1627 op->run = v->run; | |
1628 op->data = 0; | |
1629 | |
1630 goto found; | |
1631 } | |
1632 } | |
1633 | |
6840
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1634 if (ngx_http_log_variable_compile(cf, op, &var, json) |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1635 != NGX_OK) |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1636 { |
569 | 1637 return NGX_CONF_ERROR; |
1638 } | |
1639 | |
2261 | 1640 if (flushes) { |
1641 | |
1642 flush = ngx_array_push(flushes); | |
1643 if (flush == NULL) { | |
1644 return NGX_CONF_ERROR; | |
1645 } | |
1646 | |
1647 *flush = op->data; /* variable index */ | |
1648 } | |
1649 | |
573 | 1650 found: |
1651 | |
1652 continue; | |
1653 } | |
1654 | |
1655 i++; | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1656 |
880 | 1657 while (i < value[s].len && value[s].data[i] != '$') { |
573 | 1658 i++; |
1659 } | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1660 |
573 | 1661 len = &value[s].data[i] - data; |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1662 |
573 | 1663 if (len) { |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1664 |
573 | 1665 op->len = len; |
1666 op->getlen = NULL; | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1667 |
573 | 1668 if (len <= sizeof(uintptr_t)) { |
1669 op->run = ngx_http_log_copy_short; | |
1670 op->data = 0; | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1671 |
573 | 1672 while (len--) { |
1673 op->data <<= 8; | |
1674 op->data |= data[len]; | |
1675 } | |
1676 | |
1677 } else { | |
1678 op->run = ngx_http_log_copy_long; | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1679 |
2049 | 1680 p = ngx_pnalloc(cf->pool, len); |
573 | 1681 if (p == NULL) { |
1682 return NGX_CONF_ERROR; | |
1683 } | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1684 |
573 | 1685 ngx_memcpy(p, data, len); |
1686 op->data = (uintptr_t) p; | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1687 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1688 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1689 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1690 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1691 |
569 | 1692 return NGX_CONF_OK; |
1693 | |
1694 invalid: | |
1695 | |
1696 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "invalid parameter \"%s\"", data); | |
1697 | |
1698 return NGX_CONF_ERROR; | |
1699 } | |
1700 | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1701 |
2072 | 1702 static char * |
1703 ngx_http_log_open_file_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
1704 { | |
1705 ngx_http_log_loc_conf_t *llcf = conf; | |
1706 | |
1707 time_t inactive, valid; | |
1708 ngx_str_t *value, s; | |
1709 ngx_int_t max, min_uses; | |
1710 ngx_uint_t i; | |
1711 | |
1712 if (llcf->open_file_cache != NGX_CONF_UNSET_PTR) { | |
1713 return "is duplicate"; | |
1714 } | |
1715 | |
1716 value = cf->args->elts; | |
1717 | |
1718 max = 0; | |
1719 inactive = 10; | |
1720 valid = 60; | |
1721 min_uses = 1; | |
1722 | |
1723 for (i = 1; i < cf->args->nelts; i++) { | |
1724 | |
1725 if (ngx_strncmp(value[i].data, "max=", 4) == 0) { | |
1726 | |
1727 max = ngx_atoi(value[i].data + 4, value[i].len - 4); | |
1728 if (max == NGX_ERROR) { | |
1729 goto failed; | |
1730 } | |
1731 | |
1732 continue; | |
1733 } | |
1734 | |
1735 if (ngx_strncmp(value[i].data, "inactive=", 9) == 0) { | |
1736 | |
1737 s.len = value[i].len - 9; | |
1738 s.data = value[i].data + 9; | |
1739 | |
1740 inactive = ngx_parse_time(&s, 1); | |
4474 | 1741 if (inactive == (time_t) NGX_ERROR) { |
2072 | 1742 goto failed; |
1743 } | |
1744 | |
1745 continue; | |
1746 } | |
1747 | |
1748 if (ngx_strncmp(value[i].data, "min_uses=", 9) == 0) { | |
1749 | |
1750 min_uses = ngx_atoi(value[i].data + 9, value[i].len - 9); | |
1751 if (min_uses == NGX_ERROR) { | |
1752 goto failed; | |
1753 } | |
1754 | |
1755 continue; | |
1756 } | |
1757 | |
1758 if (ngx_strncmp(value[i].data, "valid=", 6) == 0) { | |
1759 | |
1760 s.len = value[i].len - 6; | |
1761 s.data = value[i].data + 6; | |
1762 | |
1763 valid = ngx_parse_time(&s, 1); | |
4474 | 1764 if (valid == (time_t) NGX_ERROR) { |
2072 | 1765 goto failed; |
1766 } | |
1767 | |
1768 continue; | |
1769 } | |
1770 | |
1771 if (ngx_strcmp(value[i].data, "off") == 0) { | |
1772 | |
1773 llcf->open_file_cache = NULL; | |
1774 | |
1775 continue; | |
1776 } | |
1777 | |
1778 failed: | |
1779 | |
1780 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1781 "invalid \"open_log_file_cache\" parameter \"%V\"", | |
1782 &value[i]); | |
1783 return NGX_CONF_ERROR; | |
1784 } | |
1785 | |
1786 if (llcf->open_file_cache == NULL) { | |
1787 return NGX_CONF_OK; | |
1788 } | |
1789 | |
1790 if (max == 0) { | |
1791 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1792 "\"open_log_file_cache\" must have \"max\" parameter"); | |
1793 return NGX_CONF_ERROR; | |
1794 } | |
1795 | |
1796 llcf->open_file_cache = ngx_open_file_cache_init(cf->pool, max, inactive); | |
1797 | |
1798 if (llcf->open_file_cache) { | |
1799 | |
1800 llcf->open_file_cache_valid = valid; | |
1801 llcf->open_file_cache_min_uses = min_uses; | |
1802 | |
1803 return NGX_CONF_OK; | |
1804 } | |
1805 | |
1806 return NGX_CONF_ERROR; | |
1807 } | |
1808 | |
1809 | |
569 | 1810 static ngx_int_t |
573 | 1811 ngx_http_log_init(ngx_conf_t *cf) |
569 | 1812 { |
573 | 1813 ngx_str_t *value; |
1814 ngx_array_t a; | |
581 | 1815 ngx_http_handler_pt *h; |
573 | 1816 ngx_http_log_fmt_t *fmt; |
1817 ngx_http_log_main_conf_t *lmcf; | |
569 | 1818 ngx_http_core_main_conf_t *cmcf; |
1819 | |
573 | 1820 lmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_log_module); |
1821 | |
1822 if (lmcf->combined_used) { | |
1823 if (ngx_array_init(&a, cf->pool, 1, sizeof(ngx_str_t)) != NGX_OK) { | |
1824 return NGX_ERROR; | |
1825 } | |
1826 | |
1827 value = ngx_array_push(&a); | |
1828 if (value == NULL) { | |
1829 return NGX_ERROR; | |
1830 } | |
1831 | |
1832 *value = ngx_http_combined_fmt; | |
1833 fmt = lmcf->formats.elts; | |
1834 | |
2261 | 1835 if (ngx_http_log_compile_format(cf, NULL, fmt->ops, &a, 0) |
573 | 1836 != NGX_CONF_OK) |
1837 { | |
1838 return NGX_ERROR; | |
1839 } | |
1840 } | |
1841 | |
1842 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module); | |
569 | 1843 |
581 | 1844 h = ngx_array_push(&cmcf->phases[NGX_HTTP_LOG_PHASE].handlers); |
1845 if (h == NULL) { | |
1846 return NGX_ERROR; | |
1847 } | |
1848 | |
1849 *h = ngx_http_log_handler; | |
569 | 1850 |
1851 return NGX_OK; | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1852 } |