Mercurial > hg > nginx
annotate src/http/modules/ngx_http_log_module.c @ 6986:0cdee26605f3
Cleaned up r->headers_out.headers allocation error handling.
If initialization of a header failed for some reason after ngx_list_push(),
leaving the header as is can result in uninitialized memory access by
the header filter or the log module. The fix is to clear partially
initialized headers in case of errors.
For the Cache-Control header, the fix is to postpone pushing
r->headers_out.cache_control until its value is completed.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Thu, 20 Apr 2017 18:26:37 +0300 |
parents | 3fb9b5eb75c0 |
children | 265c29b0b8b8 |
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 { | |
6948
3fb9b5eb75c0
Fixed ngx_open_cached_file() error handling.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6927
diff
changeset
|
555 if (of.err == 0) { |
3fb9b5eb75c0
Fixed ngx_open_cached_file() error handling.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6927
diff
changeset
|
556 /* simulate successful logging */ |
3fb9b5eb75c0
Fixed ngx_open_cached_file() error handling.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6927
diff
changeset
|
557 return len; |
3fb9b5eb75c0
Fixed ngx_open_cached_file() error handling.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6927
diff
changeset
|
558 } |
3fb9b5eb75c0
Fixed ngx_open_cached_file() error handling.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6927
diff
changeset
|
559 |
2072 | 560 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
|
561 "%s \"%s\" failed", of.failed, log.data); |
4499
778ef9c3fd2d
Fixed spelling in single-line comments.
Ruslan Ermilov <ru@nginx.com>
parents:
4494
diff
changeset
|
562 /* simulate successful logging */ |
2077 | 563 return len; |
2072 | 564 } |
565 | |
566 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
567 "http log #%d", of.fd); | |
568 | |
569 n = ngx_write_fd(of.fd, buf, len); | |
570 | |
571 return n; | |
572 } | |
573 | |
574 | |
4988
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
575 #if (NGX_ZLIB) |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
576 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
577 static ssize_t |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
578 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
|
579 ngx_log_t *log) |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
580 { |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
581 int rc, wbits, memlevel; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
582 u_char *out; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
583 size_t size; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
584 ssize_t n; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
585 z_stream zstream; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
586 ngx_err_t err; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
587 ngx_pool_t *pool; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
588 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
589 wbits = MAX_WBITS; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
590 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
|
591 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
592 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
|
593 wbits--; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
594 memlevel--; |
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 /* |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
598 * 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
|
599 * 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
|
600 */ |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
601 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
602 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
|
603 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
604 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
|
605 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
606 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
|
607 if (pool == NULL) { |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
608 /* simulate successful logging */ |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
609 return len; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
610 } |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
611 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
612 pool->log = log; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
613 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
614 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
|
615 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
|
616 zstream.opaque = pool; |
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 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
|
619 if (out == NULL) { |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
620 goto done; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
621 } |
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 zstream.next_in = buf; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
624 zstream.avail_in = len; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
625 zstream.next_out = out; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
626 zstream.avail_out = size; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
627 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
628 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
|
629 Z_DEFAULT_STRATEGY); |
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 if (rc != Z_OK) { |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
632 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
|
633 goto done; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
634 } |
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 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
|
637 "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
|
638 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
|
639 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
|
640 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
641 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
|
642 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
643 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
|
644 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
|
645 "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
|
646 goto done; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
647 } |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
648 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
649 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
|
650 "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
|
651 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
|
652 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
|
653 rc); |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
654 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
655 size -= zstream.avail_out; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
656 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
657 rc = deflateEnd(&zstream); |
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 if (rc != Z_OK) { |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
660 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
|
661 goto done; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
662 } |
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 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
|
665 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
666 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
|
667 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
|
668 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
669 ngx_destroy_pool(pool); |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
670 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
671 ngx_set_errno(err); |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
672 return -1; |
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 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
675 done: |
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 ngx_destroy_pool(pool); |
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 /* simulate successful logging */ |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
680 return len; |
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 |
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 static void * |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
685 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
|
686 { |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
687 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
|
688 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
689 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
|
690 "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
|
691 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
692 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
|
693 } |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
694 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
695 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
696 static void |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
697 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
|
698 { |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
699 #if 0 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
700 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
|
701 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
702 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
|
703 #endif |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
704 } |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
705 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
706 #endif |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
707 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
708 |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
709 static void |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
710 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
|
711 { |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
712 size_t len; |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
713 ssize_t n; |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
714 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
|
715 |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
716 buffer = file->data; |
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 len = buffer->pos - buffer->start; |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
719 |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
720 if (len == 0) { |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
721 return; |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
722 } |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
723 |
4988
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
724 #if (NGX_ZLIB) |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
725 if (buffer->gzip) { |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
726 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
|
727 } else { |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
728 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
|
729 } |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
730 #else |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
731 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
|
732 #endif |
4985
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 if (n == -1) { |
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, ngx_errno, |
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\" failed", |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
737 file->name.data); |
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 } 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
|
740 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
|
741 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
|
742 file->name.data, n, len); |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
743 } |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
744 |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
745 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
|
746 |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
747 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
|
748 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
|
749 } |
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 |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
752 |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
753 static void |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
754 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
|
755 { |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
756 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
|
757 "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
|
758 |
6927
c36d160cd4e0
Access log: removed dead ev->timedout check in flush timer handler.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6840
diff
changeset
|
759 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
|
760 } |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
761 |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
762 |
497 | 763 static u_char * |
764 ngx_http_log_copy_short(ngx_http_request_t *r, u_char *buf, | |
765 ngx_http_log_op_t *op) | |
479 | 766 { |
767 size_t len; | |
768 uintptr_t data; | |
769 | |
770 len = op->len; | |
771 data = op->data; | |
772 | |
773 while (len--) { | |
774 *buf++ = (u_char) (data & 0xff); | |
775 data >>= 8; | |
776 } | |
777 | |
778 return buf; | |
779 } | |
780 | |
781 | |
497 | 782 static u_char * |
783 ngx_http_log_copy_long(ngx_http_request_t *r, u_char *buf, | |
784 ngx_http_log_op_t *op) | |
479 | 785 { |
786 return ngx_cpymem(buf, (u_char *) op->data, op->len); | |
787 } | |
788 | |
789 | |
497 | 790 static u_char * |
791 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
|
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 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
|
794 *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
|
795 } else { |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
796 *buf = '.'; |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
797 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
798 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
799 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
|
800 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
801 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
802 |
497 | 803 static u_char * |
804 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
|
805 { |
178
a8ff48d26cca
nginx-0.0.1-2003-11-11-00:09:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
177
diff
changeset
|
806 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
|
807 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
|
808 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
809 |
3873 | 810 static u_char * |
811 ngx_http_log_iso8601(ngx_http_request_t *r, u_char *buf, ngx_http_log_op_t *op) | |
812 { | |
813 return ngx_cpymem(buf, ngx_cached_http_log_iso8601.data, | |
814 ngx_cached_http_log_iso8601.len); | |
815 } | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
816 |
497 | 817 static u_char * |
818 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
|
819 { |
563 | 820 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
|
821 |
563 | 822 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
|
823 |
563 | 824 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
|
825 } |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
393
diff
changeset
|
826 |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
393
diff
changeset
|
827 |
497 | 828 static u_char * |
829 ngx_http_log_request_time(ngx_http_request_t *r, u_char *buf, | |
830 ngx_http_log_op_t *op) | |
831 { | |
1179
6e2216ad2c87
$request_time has millisecond precision
Igor Sysoev <igor@sysoev.ru>
parents:
1161
diff
changeset
|
832 ngx_time_t *tp; |
6e2216ad2c87
$request_time has millisecond precision
Igor Sysoev <igor@sysoev.ru>
parents:
1161
diff
changeset
|
833 ngx_msec_int_t ms; |
6e2216ad2c87
$request_time has millisecond precision
Igor Sysoev <igor@sysoev.ru>
parents:
1161
diff
changeset
|
834 |
6e2216ad2c87
$request_time has millisecond precision
Igor Sysoev <igor@sysoev.ru>
parents:
1161
diff
changeset
|
835 tp = ngx_timeofday(); |
497 | 836 |
1640 | 837 ms = (ngx_msec_int_t) |
838 ((tp->sec - r->start_sec) * 1000 + (tp->msec - r->start_msec)); | |
3515 | 839 ms = ngx_max(ms, 0); |
497 | 840 |
5361
7094d6da2806
Win32: $request_time fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5330
diff
changeset
|
841 return ngx_sprintf(buf, "%T.%03M", (time_t) ms / 1000, ms % 1000); |
497 | 842 } |
843 | |
844 | |
845 static u_char * | |
846 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
|
847 { |
3370
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
848 ngx_uint_t status; |
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
849 |
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
850 if (r->err_status) { |
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
851 status = r->err_status; |
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
852 |
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
853 } 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
|
854 status = r->headers_out.status; |
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
855 |
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
856 } else if (r->http_version == NGX_HTTP_VERSION_9) { |
4685
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4637
diff
changeset
|
857 status = 9; |
3370
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
858 |
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
859 } else { |
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
860 status = 0; |
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
861 } |
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
862 |
4637
668ab1a21327
Zero padded the returned and logged HTTP status code, and fixed possible
Ruslan Ermilov <ru@nginx.com>
parents:
4539
diff
changeset
|
863 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
|
864 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
865 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
866 |
497 | 867 static u_char * |
573 | 868 ngx_http_log_bytes_sent(ngx_http_request_t *r, u_char *buf, |
869 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
|
870 { |
455 | 871 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
|
872 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
873 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
874 |
1271 | 875 /* |
876 * although there is a real $body_bytes_sent variable, | |
877 * this log operation code function is more optimized for logging | |
878 */ | |
879 | |
497 | 880 static u_char * |
577 | 881 ngx_http_log_body_bytes_sent(ngx_http_request_t *r, u_char *buf, |
497 | 882 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
|
883 { |
497 | 884 off_t length; |
885 | |
886 length = r->connection->sent - r->header_size; | |
887 | |
888 if (length > 0) { | |
889 return ngx_sprintf(buf, "%O", length); | |
890 } | |
891 | |
892 *buf = '0'; | |
893 | |
894 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
|
895 } |
00cafae0bdf1
nginx-0.0.1-2003-12-14-23:10:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
896 |
00cafae0bdf1
nginx-0.0.1-2003-12-14-23:10:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
897 |
497 | 898 static u_char * |
899 ngx_http_log_request_length(ngx_http_request_t *r, u_char *buf, | |
900 ngx_http_log_op_t *op) | |
475 | 901 { |
663 | 902 return ngx_sprintf(buf, "%O", r->request_length); |
475 | 903 } |
904 | |
905 | |
497 | 906 static ngx_int_t |
501 | 907 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
|
908 ngx_str_t *value, ngx_uint_t json) |
501 | 909 { |
509 | 910 ngx_int_t index; |
501 | 911 |
509 | 912 index = ngx_http_get_variable_index(cf, value); |
913 if (index == NGX_ERROR) { | |
501 | 914 return NGX_ERROR; |
915 } | |
916 | |
917 op->len = 0; | |
6840
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
918 |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
919 if (json) { |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
920 op->getlen = ngx_http_log_json_variable_getlen; |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
921 op->run = ngx_http_log_json_variable; |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
922 |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
923 } else { |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
924 op->getlen = ngx_http_log_variable_getlen; |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
925 op->run = ngx_http_log_variable; |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
926 } |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
927 |
509 | 928 op->data = index; |
501 | 929 |
930 return NGX_OK; | |
931 } | |
932 | |
933 | |
934 static size_t | |
935 ngx_http_log_variable_getlen(ngx_http_request_t *r, uintptr_t data) | |
936 { | |
2008
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
937 uintptr_t len; |
501 | 938 ngx_http_variable_value_t *value; |
939 | |
940 value = ngx_http_get_indexed_variable(r, data); | |
941 | |
573 | 942 if (value == NULL || value->not_found) { |
501 | 943 return 1; |
944 } | |
945 | |
2008
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
946 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
|
947 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
948 value->escape = len ? 1 : 0; |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
949 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
950 return value->len + len * 3; |
501 | 951 } |
952 | |
953 | |
954 static u_char * | |
955 ngx_http_log_variable(ngx_http_request_t *r, u_char *buf, ngx_http_log_op_t *op) | |
956 { | |
957 ngx_http_variable_value_t *value; | |
958 | |
959 value = ngx_http_get_indexed_variable(r, op->data); | |
960 | |
573 | 961 if (value == NULL || value->not_found) { |
501 | 962 *buf = '-'; |
963 return buf + 1; | |
964 } | |
965 | |
2008
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
966 if (value->escape == 0) { |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
967 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
|
968 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
969 } else { |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
970 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
|
971 } |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
972 } |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
973 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
974 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
975 static uintptr_t |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
976 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
|
977 { |
3275 | 978 ngx_uint_t n; |
2008
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
979 static u_char hex[] = "0123456789ABCDEF"; |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
980 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
981 static uint32_t escape[] = { |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
982 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
|
983 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
984 /* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */ |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
985 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
|
986 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
987 /* _^]\ [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
|
988 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
|
989 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
990 /* ~}| {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
|
991 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
|
992 |
4191
08d8af70760c
Improved access log escaping to better protect other software.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4133
diff
changeset
|
993 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
|
994 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
|
995 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
|
996 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
|
997 }; |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
998 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
999 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
1000 if (dst == NULL) { |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
1001 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
1002 /* 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
|
1003 |
3115 | 1004 n = 0; |
2008
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
1005 |
3275 | 1006 while (size) { |
6626
b3682580c1bd
Avoid left-shifting integers into the sign bit, which is undefined.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5927
diff
changeset
|
1007 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
|
1008 n++; |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
1009 } |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
1010 src++; |
3275 | 1011 size--; |
2008
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
1012 } |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
1013 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
1014 return (uintptr_t) n; |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
1015 } |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
1016 |
3275 | 1017 while (size) { |
6626
b3682580c1bd
Avoid left-shifting integers into the sign bit, which is undefined.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5927
diff
changeset
|
1018 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
|
1019 *dst++ = '\\'; |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
1020 *dst++ = 'x'; |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
1021 *dst++ = hex[*src >> 4]; |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
1022 *dst++ = hex[*src & 0xf]; |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
1023 src++; |
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 } else { |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
1026 *dst++ = *src++; |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
1027 } |
3275 | 1028 size--; |
2008
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
1029 } |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
1030 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
1031 return (uintptr_t) dst; |
501 | 1032 } |
1033 | |
1034 | |
6840
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1035 static size_t |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1036 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
|
1037 { |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1038 uintptr_t len; |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1039 ngx_http_variable_value_t *value; |
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 value = ngx_http_get_indexed_variable(r, data); |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1042 |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1043 if (value == NULL || value->not_found) { |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1044 return 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 |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1047 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
|
1048 |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1049 value->escape = len ? 1 : 0; |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1050 |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1051 return value->len + len; |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1052 } |
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 |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1055 static u_char * |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1056 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
|
1057 ngx_http_log_op_t *op) |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1058 { |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1059 ngx_http_variable_value_t *value; |
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 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
|
1062 |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1063 if (value == NULL || value->not_found) { |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1064 return buf; |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1065 } |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1066 |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1067 if (value->escape == 0) { |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1068 return ngx_cpymem(buf, value->data, value->len); |
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 } else { |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1071 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
|
1072 } |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1073 } |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1074 |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1075 |
497 | 1076 static void * |
1077 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
|
1078 { |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1079 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
|
1080 |
573 | 1081 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
|
1082 |
501 | 1083 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_log_main_conf_t)); |
1084 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
|
1085 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
|
1086 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1087 |
497 | 1088 if (ngx_array_init(&conf->formats, cf->pool, 4, sizeof(ngx_http_log_fmt_t)) |
573 | 1089 != NGX_OK) |
497 | 1090 { |
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; |
497 | 1092 } |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1093 |
573 | 1094 fmt = ngx_array_push(&conf->formats); |
1095 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
|
1096 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
|
1097 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1098 |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1099 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
|
1100 |
2261 | 1101 fmt->flushes = NULL; |
1102 | |
573 | 1103 fmt->ops = ngx_array_create(cf->pool, 16, sizeof(ngx_http_log_op_t)); |
1104 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
|
1105 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
|
1106 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1107 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1108 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
|
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 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1111 |
497 | 1112 static void * |
1113 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
|
1114 { |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1115 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
|
1116 |
501 | 1117 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_log_loc_conf_t)); |
1118 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
|
1119 return NULL; |
427
0d08eabe5c7b
nginx-0.0.10-2004-09-15-20:00:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
1120 } |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
1121 |
2072 | 1122 conf->open_file_cache = NGX_CONF_UNSET_PTR; |
1123 | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
1124 return conf; |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
1125 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
1126 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
1127 |
497 | 1128 static char * |
1129 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
|
1130 { |
176
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_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
|
1132 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
|
1133 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1134 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
|
1135 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
|
1136 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
|
1137 |
2072 | 1138 if (conf->open_file_cache == NGX_CONF_UNSET_PTR) { |
1139 | |
1140 conf->open_file_cache = prev->open_file_cache; | |
1141 conf->open_file_cache_valid = prev->open_file_cache_valid; | |
1142 conf->open_file_cache_min_uses = prev->open_file_cache_min_uses; | |
1143 | |
1144 if (conf->open_file_cache == NGX_CONF_UNSET_PTR) { | |
1145 conf->open_file_cache = NULL; | |
1146 } | |
1147 } | |
1148 | |
1074 | 1149 if (conf->logs || conf->off) { |
1150 return NGX_CONF_OK; | |
1151 } | |
427
0d08eabe5c7b
nginx-0.0.10-2004-09-15-20:00:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
1152 |
2078
9acbc5e7bcbd
fix variable access_log merging
Igor Sysoev <igor@sysoev.ru>
parents:
2077
diff
changeset
|
1153 conf->logs = prev->logs; |
9acbc5e7bcbd
fix variable access_log merging
Igor Sysoev <igor@sysoev.ru>
parents:
2077
diff
changeset
|
1154 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
|
1155 |
1074 | 1156 if (conf->logs || conf->off) { |
1157 return NGX_CONF_OK; | |
1158 } | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
1159 |
1074 | 1160 conf->logs = ngx_array_create(cf->pool, 2, sizeof(ngx_http_log_t)); |
1161 if (conf->logs == 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 |
1074 | 1165 log = ngx_array_push(conf->logs); |
1166 if (log == NULL) { | |
1167 return NGX_CONF_ERROR; | |
1168 } | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1169 |
5719
7f425d67f91a
Access log: fix default value, broken by cb308813b453.
Piotr Sikora <piotr@cloudflare.com>
parents:
5702
diff
changeset
|
1170 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
|
1171 |
1074 | 1172 log->file = ngx_conf_open_file(cf->cycle, &ngx_http_access_log); |
1173 if (log->file == NULL) { | |
1174 return NGX_CONF_ERROR; | |
1175 } | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1176 |
1074 | 1177 lmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_log_module); |
1178 fmt = lmcf->formats.elts; | |
1179 | |
1180 /* the default "combined" format */ | |
2261 | 1181 log->format = &fmt[0]; |
1074 | 1182 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
|
1183 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
1184 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
|
1185 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
1186 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
1187 |
497 | 1188 static char * |
1189 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
|
1190 { |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1191 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
|
1192 |
5653
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
1193 ssize_t size; |
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
1194 ngx_int_t gzip; |
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
1195 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
|
1196 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
|
1197 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
|
1198 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
|
1199 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
|
1200 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
|
1201 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
|
1202 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
|
1203 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
|
1204 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
|
1205 |
427
0d08eabe5c7b
nginx-0.0.10-2004-09-15-20:00:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
1206 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
|
1207 |
0d08eabe5c7b
nginx-0.0.10-2004-09-15-20:00:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
1208 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
|
1209 llcf->off = 1; |
3038
cd8738e76610
strict testing "access_log off"
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
1210 if (cf->args->nelts == 2) { |
cd8738e76610
strict testing "access_log off"
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
1211 return NGX_CONF_OK; |
cd8738e76610
strict testing "access_log off"
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
1212 } |
cd8738e76610
strict testing "access_log off"
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
1213 |
cd8738e76610
strict testing "access_log off"
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
1214 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
cd8738e76610
strict testing "access_log off"
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
1215 "invalid parameter \"%V\"", &value[2]); |
cd8738e76610
strict testing "access_log off"
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
1216 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
|
1217 } |
0d08eabe5c7b
nginx-0.0.10-2004-09-15-20:00:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
1218 |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1219 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
|
1220 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
|
1221 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
|
1222 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
|
1223 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1224 } |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
1225 |
393
5659d773cfa8
nginx-0.0.7-2004-07-15-20:35:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
356
diff
changeset
|
1226 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
|
1227 |
501 | 1228 log = ngx_array_push(llcf->logs); |
1229 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
|
1230 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
|
1231 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1232 |
2072 | 1233 ngx_memzero(log, sizeof(ngx_http_log_t)); |
1234 | |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
1235 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
1236 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
|
1237 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
1238 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
|
1239 if (peer == NULL) { |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
1240 return NGX_CONF_ERROR; |
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 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
1243 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
|
1244 return NGX_CONF_ERROR; |
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 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
1247 log->syslog_peer = peer; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
1248 |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
1249 goto process_formats; |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
1250 } |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
1251 |
2072 | 1252 n = ngx_http_script_variables_count(&value[1]); |
1253 | |
1254 if (n == 0) { | |
1255 log->file = ngx_conf_open_file(cf->cycle, &value[1]); | |
1256 if (log->file == NULL) { | |
1257 return NGX_CONF_ERROR; | |
1258 } | |
1259 | |
1260 } else { | |
5330
314c3d7cc3a5
Backed out f1a91825730a and 7094bd12c1ff.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5317
diff
changeset
|
1261 if (ngx_conf_full_name(cf->cycle, &value[1], 0) != NGX_OK) { |
2072 | 1262 return NGX_CONF_ERROR; |
1263 } | |
1264 | |
1265 log->script = ngx_pcalloc(cf->pool, sizeof(ngx_http_log_script_t)); | |
1266 if (log->script == NULL) { | |
1267 return NGX_CONF_ERROR; | |
1268 } | |
1269 | |
1270 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t)); | |
1271 | |
1272 sc.cf = cf; | |
1273 sc.source = &value[1]; | |
1274 sc.lengths = &log->script->lengths; | |
1275 sc.values = &log->script->values; | |
1276 sc.variables = n; | |
1277 sc.complete_lengths = 1; | |
1278 sc.complete_values = 1; | |
1279 | |
1280 if (ngx_http_script_compile(&sc) != NGX_OK) { | |
1281 return NGX_CONF_ERROR; | |
1282 } | |
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 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1284 |
5702
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
1285 process_formats: |
777202558122
Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents:
5653
diff
changeset
|
1286 |
571 | 1287 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
|
1288 name = value[2]; |
581 | 1289 |
1290 if (ngx_strcmp(name.data, "combined") == 0) { | |
1291 lmcf->combined_used = 1; | |
1292 } | |
1293 | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1294 } else { |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
1295 ngx_str_set(&name, "combined"); |
573 | 1296 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
|
1297 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1298 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1299 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
|
1300 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
|
1301 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
|
1302 && 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
|
1303 { |
2261 | 1304 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
|
1305 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
|
1306 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1307 } |
100
7ebc8b7fb816
nginx-0.0.1-2003-06-03-19:42:58 import
Igor Sysoev <igor@sysoev.ru>
parents:
99
diff
changeset
|
1308 |
4986
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1309 if (log->format == NULL) { |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1310 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
|
1311 "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
|
1312 return NGX_CONF_ERROR; |
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 |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1315 size = 0; |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1316 flush = 0; |
4988
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1317 gzip = 0; |
4986
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1318 |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1319 for (i = 3; i < cf->args->nelts; i++) { |
487 | 1320 |
4986
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1321 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
|
1322 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
|
1323 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
|
1324 |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1325 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
|
1326 |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1327 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
|
1328 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
|
1329 "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
|
1330 return NGX_CONF_ERROR; |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1331 } |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1332 |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1333 continue; |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1334 } |
571 | 1335 |
4986
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1336 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
|
1337 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
|
1338 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
|
1339 |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1340 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
|
1341 |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1342 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
|
1343 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
|
1344 "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
|
1345 return NGX_CONF_ERROR; |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1346 } |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1347 |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1348 continue; |
571 | 1349 } |
1350 | |
4988
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1351 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
|
1352 && (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
|
1353 { |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1354 #if (NGX_ZLIB) |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1355 if (size == 0) { |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1356 size = 64 * 1024; |
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 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
|
1360 gzip = Z_BEST_SPEED; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1361 continue; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1362 } |
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 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
|
1365 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
|
1366 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1367 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
|
1368 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1369 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
|
1370 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
|
1371 "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
|
1372 return NGX_CONF_ERROR; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1373 } |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1374 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1375 continue; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1376 |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1377 #else |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1378 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
|
1379 "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
|
1380 return NGX_CONF_ERROR; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1381 #endif |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1382 } |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1383 |
5653
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
1384 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
|
1385 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
|
1386 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
|
1387 |
e3016ee8dba3
Access log: fixed the "if=" parameter with buffering (ticket #625).
Valentin Bartenev <vbart@nginx.com>
parents:
5799
diff
changeset
|
1388 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
|
1389 |
e3016ee8dba3
Access log: fixed the "if=" parameter with buffering (ticket #625).
Valentin Bartenev <vbart@nginx.com>
parents:
5799
diff
changeset
|
1390 ccv.cf = cf; |
e3016ee8dba3
Access log: fixed the "if=" parameter with buffering (ticket #625).
Valentin Bartenev <vbart@nginx.com>
parents:
5799
diff
changeset
|
1391 ccv.value = &s; |
e3016ee8dba3
Access log: fixed the "if=" parameter with buffering (ticket #625).
Valentin Bartenev <vbart@nginx.com>
parents:
5799
diff
changeset
|
1392 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
|
1393 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
|
1394 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
|
1395 return NGX_CONF_ERROR; |
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 |
e3016ee8dba3
Access log: fixed the "if=" parameter with buffering (ticket #625).
Valentin Bartenev <vbart@nginx.com>
parents:
5799
diff
changeset
|
1398 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
|
1399 return NGX_CONF_ERROR; |
e3016ee8dba3
Access log: fixed the "if=" parameter with buffering (ticket #625).
Valentin Bartenev <vbart@nginx.com>
parents:
5799
diff
changeset
|
1400 } |
e3016ee8dba3
Access log: fixed the "if=" parameter with buffering (ticket #625).
Valentin Bartenev <vbart@nginx.com>
parents:
5799
diff
changeset
|
1401 |
e3016ee8dba3
Access log: fixed the "if=" parameter with buffering (ticket #625).
Valentin Bartenev <vbart@nginx.com>
parents:
5799
diff
changeset
|
1402 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
|
1403 |
5653
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
1404 continue; |
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
1405 } |
cb308813b453
Access log: the "if" parameter of the "access_log" directive.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5361
diff
changeset
|
1406 |
4986
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1407 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
|
1408 "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
|
1409 return NGX_CONF_ERROR; |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1410 } |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1411 |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1412 if (flush && size == 0) { |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1413 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
|
1414 "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
|
1415 &value[1]); |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1416 return NGX_CONF_ERROR; |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1417 } |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1418 |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1419 if (size) { |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1420 |
2072 | 1421 if (log->script) { |
1422 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
|
1423 "buffered logs cannot have variables in name"); |
2072 | 1424 return NGX_CONF_ERROR; |
1425 } | |
1426 | |
5799
b1f8285297a7
Access log: allowed logs to syslog with "if=" (ticket #596).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5719
diff
changeset
|
1427 if (log->syslog_peer) { |
b1f8285297a7
Access log: allowed logs to syslog with "if=" (ticket #596).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5719
diff
changeset
|
1428 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
|
1429 "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
|
1430 return NGX_CONF_ERROR; |
b1f8285297a7
Access log: allowed logs to syslog with "if=" (ticket #596).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5719
diff
changeset
|
1431 } |
b1f8285297a7
Access log: allowed logs to syslog with "if=" (ticket #596).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5719
diff
changeset
|
1432 |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1433 if (log->file->data) { |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1434 buffer = log->file->data; |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1435 |
4986
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1436 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
|
1437 || buffer->flush != flush |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1438 || buffer->gzip != gzip) |
4986
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1439 { |
4984
7737f0d788c1
Access log: fixed redundant buffer reallocation.
Valentin Bartenev <vbart@nginx.com>
parents:
4893
diff
changeset
|
1440 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
|
1441 "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
|
1442 "with conflicting parameters", |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1443 &value[1]); |
4984
7737f0d788c1
Access log: fixed redundant buffer reallocation.
Valentin Bartenev <vbart@nginx.com>
parents:
4893
diff
changeset
|
1444 return NGX_CONF_ERROR; |
7737f0d788c1
Access log: fixed redundant buffer reallocation.
Valentin Bartenev <vbart@nginx.com>
parents:
4893
diff
changeset
|
1445 } |
7737f0d788c1
Access log: fixed redundant buffer reallocation.
Valentin Bartenev <vbart@nginx.com>
parents:
4893
diff
changeset
|
1446 |
7737f0d788c1
Access log: fixed redundant buffer reallocation.
Valentin Bartenev <vbart@nginx.com>
parents:
4893
diff
changeset
|
1447 return NGX_CONF_OK; |
571 | 1448 } |
1449 | |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1450 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
|
1451 if (buffer == NULL) { |
571 | 1452 return NGX_CONF_ERROR; |
1453 } | |
1454 | |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1455 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
|
1456 if (buffer->start == NULL) { |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1457 return NGX_CONF_ERROR; |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1458 } |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1459 |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1460 buffer->pos = buffer->start; |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1461 buffer->last = buffer->start + size; |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1462 |
4986
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1463 if (flush) { |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1464 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
|
1465 if (buffer->event == NULL) { |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1466 return NGX_CONF_ERROR; |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1467 } |
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->event->data = log->file; |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1470 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
|
1471 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
|
1472 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
|
1473 |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1474 buffer->flush = flush; |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1475 } |
3efc49b156d9
Access log: the "flush" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4985
diff
changeset
|
1476 |
4988
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1477 buffer->gzip = gzip; |
3849bb380605
Access log: the "gzip" parameter of the "access_log" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4986
diff
changeset
|
1478 |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1479 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
|
1480 log->file->data = buffer; |
571 | 1481 } |
1482 | |
1483 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
|
1484 } |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1485 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1486 |
497 | 1487 static char * |
1488 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
|
1489 { |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1490 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
|
1491 |
573 | 1492 ngx_str_t *value; |
1493 ngx_uint_t i; | |
1494 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
|
1495 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1496 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
|
1497 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1498 fmt = lmcf->formats.elts; |
573 | 1499 for (i = 0; i < lmcf->formats.nelts; i++) { |
1500 if (fmt[i].name.len == value[1].len | |
1501 && 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
|
1502 { |
2036 | 1503 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
1504 "duplicate \"log_format\" name \"%V\"", | |
1505 &value[1]); | |
1506 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
|
1507 } |
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 |
501 | 1510 fmt = ngx_array_push(&lmcf->formats); |
1511 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
|
1512 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
|
1513 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1514 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1515 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
|
1516 |
2261 | 1517 fmt->flushes = ngx_array_create(cf->pool, 4, sizeof(ngx_int_t)); |
1518 if (fmt->flushes == NULL) { | |
1519 return NGX_CONF_ERROR; | |
1520 } | |
1521 | |
573 | 1522 fmt->ops = ngx_array_create(cf->pool, 16, sizeof(ngx_http_log_op_t)); |
501 | 1523 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
|
1524 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
|
1525 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1526 |
2261 | 1527 return ngx_http_log_compile_format(cf, fmt->flushes, fmt->ops, cf->args, 2); |
573 | 1528 } |
1529 | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1530 |
573 | 1531 static char * |
2261 | 1532 ngx_http_log_compile_format(ngx_conf_t *cf, ngx_array_t *flushes, |
1533 ngx_array_t *ops, ngx_array_t *args, ngx_uint_t s) | |
573 | 1534 { |
880 | 1535 u_char *data, *p, ch; |
1536 size_t i, len; | |
1537 ngx_str_t *value, var; | |
2261 | 1538 ngx_int_t *flush; |
6840
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1539 ngx_uint_t bracket, json; |
880 | 1540 ngx_http_log_op_t *op; |
1541 ngx_http_log_var_t *v; | |
573 | 1542 |
6840
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1543 json = 0; |
573 | 1544 value = args->elts; |
1545 | |
6840
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1546 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
|
1547 data = value[s].data + 7; |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1548 |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1549 if (ngx_strcmp(data, "json") == 0) { |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1550 json = 1; |
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 } else if (ngx_strcmp(data, "default") != 0) { |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1553 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
|
1554 "unknown log format escaping \"%s\"", data); |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1555 return NGX_CONF_ERROR; |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1556 } |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1557 |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1558 s++; |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1559 } |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1560 |
573 | 1561 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
|
1562 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1563 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
|
1564 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1565 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
|
1566 |
573 | 1567 op = ngx_array_push(ops); |
501 | 1568 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
|
1569 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
|
1570 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1571 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1572 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
|
1573 |
880 | 1574 if (value[s].data[i] == '$') { |
569 | 1575 |
1576 if (++i == value[s].len) { | |
1577 goto invalid; | |
1578 } | |
1579 | |
1580 if (value[s].data[i] == '{') { | |
1581 bracket = 1; | |
1582 | |
1583 if (++i == value[s].len) { | |
1584 goto invalid; | |
1585 } | |
1586 | |
1587 var.data = &value[s].data[i]; | |
1588 | |
1589 } else { | |
1590 bracket = 0; | |
1591 var.data = &value[s].data[i]; | |
1592 } | |
1593 | |
1594 for (var.len = 0; i < value[s].len; i++, var.len++) { | |
1595 ch = value[s].data[i]; | |
1596 | |
1597 if (ch == '}' && bracket) { | |
1598 i++; | |
1599 bracket = 0; | |
1600 break; | |
1601 } | |
1602 | |
1603 if ((ch >= 'A' && ch <= 'Z') | |
1604 || (ch >= 'a' && ch <= 'z') | |
1605 || (ch >= '0' && ch <= '9') | |
1606 || ch == '_') | |
1607 { | |
1608 continue; | |
1609 } | |
1610 | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1611 break; |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1612 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1613 |
569 | 1614 if (bracket) { |
1615 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1616 "the closing bracket in \"%V\" " | |
1617 "variable is missing", &var); | |
1618 return NGX_CONF_ERROR; | |
1619 } | |
1620 | |
1621 if (var.len == 0) { | |
1622 goto invalid; | |
1623 } | |
1624 | |
573 | 1625 for (v = ngx_http_log_vars; v->name.len; v++) { |
1626 | |
1627 if (v->name.len == var.len | |
1628 && ngx_strncmp(v->name.data, var.data, var.len) == 0) | |
1629 { | |
1630 op->len = v->len; | |
1631 op->getlen = NULL; | |
1632 op->run = v->run; | |
1633 op->data = 0; | |
1634 | |
1635 goto found; | |
1636 } | |
1637 } | |
1638 | |
6840
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1639 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
|
1640 != NGX_OK) |
0cf4e82e7c48
Access log: support for json escaping.
Valentin Bartenev <vbart@nginx.com>
parents:
6626
diff
changeset
|
1641 { |
569 | 1642 return NGX_CONF_ERROR; |
1643 } | |
1644 | |
2261 | 1645 if (flushes) { |
1646 | |
1647 flush = ngx_array_push(flushes); | |
1648 if (flush == NULL) { | |
1649 return NGX_CONF_ERROR; | |
1650 } | |
1651 | |
1652 *flush = op->data; /* variable index */ | |
1653 } | |
1654 | |
573 | 1655 found: |
1656 | |
1657 continue; | |
1658 } | |
1659 | |
1660 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
|
1661 |
880 | 1662 while (i < value[s].len && value[s].data[i] != '$') { |
573 | 1663 i++; |
1664 } | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1665 |
573 | 1666 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
|
1667 |
573 | 1668 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
|
1669 |
573 | 1670 op->len = len; |
1671 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
|
1672 |
573 | 1673 if (len <= sizeof(uintptr_t)) { |
1674 op->run = ngx_http_log_copy_short; | |
1675 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
|
1676 |
573 | 1677 while (len--) { |
1678 op->data <<= 8; | |
1679 op->data |= data[len]; | |
1680 } | |
1681 | |
1682 } else { | |
1683 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
|
1684 |
2049 | 1685 p = ngx_pnalloc(cf->pool, len); |
573 | 1686 if (p == NULL) { |
1687 return NGX_CONF_ERROR; | |
1688 } | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1689 |
573 | 1690 ngx_memcpy(p, data, len); |
1691 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
|
1692 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1693 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1694 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1695 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1696 |
569 | 1697 return NGX_CONF_OK; |
1698 | |
1699 invalid: | |
1700 | |
1701 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "invalid parameter \"%s\"", data); | |
1702 | |
1703 return NGX_CONF_ERROR; | |
1704 } | |
1705 | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1706 |
2072 | 1707 static char * |
1708 ngx_http_log_open_file_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
1709 { | |
1710 ngx_http_log_loc_conf_t *llcf = conf; | |
1711 | |
1712 time_t inactive, valid; | |
1713 ngx_str_t *value, s; | |
1714 ngx_int_t max, min_uses; | |
1715 ngx_uint_t i; | |
1716 | |
1717 if (llcf->open_file_cache != NGX_CONF_UNSET_PTR) { | |
1718 return "is duplicate"; | |
1719 } | |
1720 | |
1721 value = cf->args->elts; | |
1722 | |
1723 max = 0; | |
1724 inactive = 10; | |
1725 valid = 60; | |
1726 min_uses = 1; | |
1727 | |
1728 for (i = 1; i < cf->args->nelts; i++) { | |
1729 | |
1730 if (ngx_strncmp(value[i].data, "max=", 4) == 0) { | |
1731 | |
1732 max = ngx_atoi(value[i].data + 4, value[i].len - 4); | |
1733 if (max == NGX_ERROR) { | |
1734 goto failed; | |
1735 } | |
1736 | |
1737 continue; | |
1738 } | |
1739 | |
1740 if (ngx_strncmp(value[i].data, "inactive=", 9) == 0) { | |
1741 | |
1742 s.len = value[i].len - 9; | |
1743 s.data = value[i].data + 9; | |
1744 | |
1745 inactive = ngx_parse_time(&s, 1); | |
4474 | 1746 if (inactive == (time_t) NGX_ERROR) { |
2072 | 1747 goto failed; |
1748 } | |
1749 | |
1750 continue; | |
1751 } | |
1752 | |
1753 if (ngx_strncmp(value[i].data, "min_uses=", 9) == 0) { | |
1754 | |
1755 min_uses = ngx_atoi(value[i].data + 9, value[i].len - 9); | |
1756 if (min_uses == NGX_ERROR) { | |
1757 goto failed; | |
1758 } | |
1759 | |
1760 continue; | |
1761 } | |
1762 | |
1763 if (ngx_strncmp(value[i].data, "valid=", 6) == 0) { | |
1764 | |
1765 s.len = value[i].len - 6; | |
1766 s.data = value[i].data + 6; | |
1767 | |
1768 valid = ngx_parse_time(&s, 1); | |
4474 | 1769 if (valid == (time_t) NGX_ERROR) { |
2072 | 1770 goto failed; |
1771 } | |
1772 | |
1773 continue; | |
1774 } | |
1775 | |
1776 if (ngx_strcmp(value[i].data, "off") == 0) { | |
1777 | |
1778 llcf->open_file_cache = NULL; | |
1779 | |
1780 continue; | |
1781 } | |
1782 | |
1783 failed: | |
1784 | |
1785 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1786 "invalid \"open_log_file_cache\" parameter \"%V\"", | |
1787 &value[i]); | |
1788 return NGX_CONF_ERROR; | |
1789 } | |
1790 | |
1791 if (llcf->open_file_cache == NULL) { | |
1792 return NGX_CONF_OK; | |
1793 } | |
1794 | |
1795 if (max == 0) { | |
1796 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1797 "\"open_log_file_cache\" must have \"max\" parameter"); | |
1798 return NGX_CONF_ERROR; | |
1799 } | |
1800 | |
1801 llcf->open_file_cache = ngx_open_file_cache_init(cf->pool, max, inactive); | |
1802 | |
1803 if (llcf->open_file_cache) { | |
1804 | |
1805 llcf->open_file_cache_valid = valid; | |
1806 llcf->open_file_cache_min_uses = min_uses; | |
1807 | |
1808 return NGX_CONF_OK; | |
1809 } | |
1810 | |
1811 return NGX_CONF_ERROR; | |
1812 } | |
1813 | |
1814 | |
569 | 1815 static ngx_int_t |
573 | 1816 ngx_http_log_init(ngx_conf_t *cf) |
569 | 1817 { |
573 | 1818 ngx_str_t *value; |
1819 ngx_array_t a; | |
581 | 1820 ngx_http_handler_pt *h; |
573 | 1821 ngx_http_log_fmt_t *fmt; |
1822 ngx_http_log_main_conf_t *lmcf; | |
569 | 1823 ngx_http_core_main_conf_t *cmcf; |
1824 | |
573 | 1825 lmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_log_module); |
1826 | |
1827 if (lmcf->combined_used) { | |
1828 if (ngx_array_init(&a, cf->pool, 1, sizeof(ngx_str_t)) != NGX_OK) { | |
1829 return NGX_ERROR; | |
1830 } | |
1831 | |
1832 value = ngx_array_push(&a); | |
1833 if (value == NULL) { | |
1834 return NGX_ERROR; | |
1835 } | |
1836 | |
1837 *value = ngx_http_combined_fmt; | |
1838 fmt = lmcf->formats.elts; | |
1839 | |
2261 | 1840 if (ngx_http_log_compile_format(cf, NULL, fmt->ops, &a, 0) |
573 | 1841 != NGX_CONF_OK) |
1842 { | |
1843 return NGX_ERROR; | |
1844 } | |
1845 } | |
1846 | |
1847 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module); | |
569 | 1848 |
581 | 1849 h = ngx_array_push(&cmcf->phases[NGX_HTTP_LOG_PHASE].handlers); |
1850 if (h == NULL) { | |
1851 return NGX_ERROR; | |
1852 } | |
1853 | |
1854 *h = ngx_http_log_handler; | |
569 | 1855 |
1856 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
|
1857 } |