Mercurial > hg > nginx
annotate src/http/modules/ngx_http_log_module.c @ 4985:a0599b56e748
Reopening log files code moved to a separate function.
The code refactored in a way to call custom handler that can do appropriate
cleanup work (if any), like flushing buffers, finishing compress streams,
finalizing connections to log daemon, etc..
author | Valentin Bartenev <vbart@nginx.com> |
---|---|
date | Sun, 23 Dec 2012 15:36:52 +0000 |
parents | 7737f0d788c1 |
children | 3efc49b156d9 |
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 |
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
12 |
880 | 13 typedef struct ngx_http_log_op_s ngx_http_log_op_t; |
14 | |
15 typedef u_char *(*ngx_http_log_op_run_pt) (ngx_http_request_t *r, u_char *buf, | |
16 ngx_http_log_op_t *op); | |
17 | |
18 typedef size_t (*ngx_http_log_op_getlen_pt) (ngx_http_request_t *r, | |
19 uintptr_t data); | |
20 | |
21 | |
22 struct ngx_http_log_op_s { | |
23 size_t len; | |
24 ngx_http_log_op_getlen_pt getlen; | |
25 ngx_http_log_op_run_pt run; | |
26 uintptr_t data; | |
27 }; | |
28 | |
573 | 29 |
30 typedef struct { | |
31 ngx_str_t name; | |
2261 | 32 ngx_array_t *flushes; |
573 | 33 ngx_array_t *ops; /* array of ngx_http_log_op_t */ |
34 } ngx_http_log_fmt_t; | |
35 | |
657 | 36 |
573 | 37 typedef struct { |
38 ngx_array_t formats; /* array of ngx_http_log_fmt_t */ | |
39 ngx_uint_t combined_used; /* unsigned combined_used:1 */ | |
40 } ngx_http_log_main_conf_t; | |
41 | |
657 | 42 |
573 | 43 typedef struct { |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
44 u_char *start; |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
45 u_char *pos; |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
46 u_char *last; |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
47 } ngx_http_log_buf_t; |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
48 |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
49 |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
50 typedef struct { |
2072 | 51 ngx_array_t *lengths; |
52 ngx_array_t *values; | |
53 } ngx_http_log_script_t; | |
54 | |
55 | |
56 typedef struct { | |
573 | 57 ngx_open_file_t *file; |
2072 | 58 ngx_http_log_script_t *script; |
633 | 59 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
|
60 time_t error_log_time; |
2261 | 61 ngx_http_log_fmt_t *format; |
573 | 62 } ngx_http_log_t; |
63 | |
657 | 64 |
573 | 65 typedef struct { |
66 ngx_array_t *logs; /* array of ngx_http_log_t */ | |
2072 | 67 |
68 ngx_open_file_cache_t *open_file_cache; | |
69 time_t open_file_cache_valid; | |
70 ngx_uint_t open_file_cache_min_uses; | |
71 | |
573 | 72 ngx_uint_t off; /* unsigned off:1 */ |
73 } ngx_http_log_loc_conf_t; | |
74 | |
75 | |
76 typedef struct { | |
77 ngx_str_t name; | |
78 size_t len; | |
79 ngx_http_log_op_run_pt run; | |
80 } ngx_http_log_var_t; | |
81 | |
82 | |
1071
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
83 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
|
84 u_char *buf, size_t len); |
2072 | 85 static ssize_t ngx_http_log_script_write(ngx_http_request_t *r, |
86 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
|
87 |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
88 static void 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
|
89 |
290
87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
282
diff
changeset
|
90 static u_char *ngx_http_log_pipe(ngx_http_request_t *r, u_char *buf, |
497 | 91 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
|
92 static u_char *ngx_http_log_time(ngx_http_request_t *r, u_char *buf, |
497 | 93 ngx_http_log_op_t *op); |
3873 | 94 static u_char *ngx_http_log_iso8601(ngx_http_request_t *r, u_char *buf, |
95 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
|
96 static u_char *ngx_http_log_msec(ngx_http_request_t *r, u_char *buf, |
497 | 97 ngx_http_log_op_t *op); |
98 static u_char *ngx_http_log_request_time(ngx_http_request_t *r, u_char *buf, | |
99 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
|
100 static u_char *ngx_http_log_status(ngx_http_request_t *r, u_char *buf, |
497 | 101 ngx_http_log_op_t *op); |
573 | 102 static u_char *ngx_http_log_bytes_sent(ngx_http_request_t *r, u_char *buf, |
497 | 103 ngx_http_log_op_t *op); |
577 | 104 static u_char *ngx_http_log_body_bytes_sent(ngx_http_request_t *r, |
573 | 105 u_char *buf, ngx_http_log_op_t *op); |
475 | 106 static u_char *ngx_http_log_request_length(ngx_http_request_t *r, u_char *buf, |
497 | 107 ngx_http_log_op_t *op); |
479 | 108 |
501 | 109 static ngx_int_t ngx_http_log_variable_compile(ngx_conf_t *cf, |
110 ngx_http_log_op_t *op, ngx_str_t *value); | |
111 static size_t ngx_http_log_variable_getlen(ngx_http_request_t *r, | |
112 uintptr_t data); | |
113 static u_char *ngx_http_log_variable(ngx_http_request_t *r, u_char *buf, | |
114 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
|
115 static uintptr_t ngx_http_log_escape(u_char *dst, u_char *src, size_t size); |
501 | 116 |
117 | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
118 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
|
119 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
|
120 static char *ngx_http_log_merge_loc_conf(ngx_conf_t *cf, void *parent, |
497 | 121 void *child); |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
122 static char *ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd, |
497 | 123 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
|
124 static char *ngx_http_log_set_format(ngx_conf_t *cf, ngx_command_t *cmd, |
497 | 125 void *conf); |
573 | 126 static char *ngx_http_log_compile_format(ngx_conf_t *cf, |
2261 | 127 ngx_array_t *flushes, ngx_array_t *ops, ngx_array_t *args, ngx_uint_t s); |
2072 | 128 static char *ngx_http_log_open_file_cache(ngx_conf_t *cf, ngx_command_t *cmd, |
129 void *conf); | |
573 | 130 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
|
131 |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
132 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
133 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
|
134 |
497 | 135 { ngx_string("log_format"), |
136 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_2MORE, | |
137 ngx_http_log_set_format, | |
138 NGX_HTTP_MAIN_CONF_OFFSET, | |
139 0, | |
140 NULL }, | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
141 |
497 | 142 { ngx_string("access_log"), |
645 | 143 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF |
1562
bb662e047a21
allow access_log inside limit_except
Igor Sysoev <igor@sysoev.ru>
parents:
1271
diff
changeset
|
144 |NGX_HTTP_LMT_CONF|NGX_CONF_TAKE123, |
497 | 145 ngx_http_log_set_log, |
146 NGX_HTTP_LOC_CONF_OFFSET, | |
147 0, | |
148 NULL }, | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
149 |
2072 | 150 { ngx_string("open_log_file_cache"), |
151 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1234, | |
152 ngx_http_log_open_file_cache, | |
153 NGX_HTTP_LOC_CONF_OFFSET, | |
154 0, | |
155 NULL }, | |
156 | |
497 | 157 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
|
158 }; |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
159 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
160 |
667 | 161 static ngx_http_module_t ngx_http_log_module_ctx = { |
880 | 162 NULL, /* preconfiguration */ |
573 | 163 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
|
164 |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
165 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
|
166 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
|
167 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
168 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
|
169 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
|
170 |
4499
778ef9c3fd2d
Fixed spelling in single-line comments.
Ruslan Ermilov <ru@nginx.com>
parents:
4494
diff
changeset
|
171 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
|
172 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
|
173 }; |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
174 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
175 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
176 ngx_module_t ngx_http_log_module = { |
509 | 177 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
|
178 &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
|
179 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
|
180 NGX_HTTP_MODULE, /* module type */ |
541 | 181 NULL, /* init master */ |
573 | 182 NULL, /* init module */ |
541 | 183 NULL, /* init process */ |
184 NULL, /* init thread */ | |
185 NULL, /* exit thread */ | |
186 NULL, /* exit process */ | |
187 NULL, /* exit master */ | |
188 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
|
189 }; |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
190 |
26
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
191 |
1074 | 192 static ngx_str_t ngx_http_access_log = ngx_string(NGX_HTTP_LOG_PATH); |
573 | 193 |
194 | |
195 static ngx_str_t ngx_http_combined_fmt = | |
581 | 196 ngx_string("$remote_addr - $remote_user [$time_local] " |
577 | 197 "\"$request\" $status $body_bytes_sent " |
573 | 198 "\"$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
|
199 |
26
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
200 |
573 | 201 static ngx_http_log_var_t ngx_http_log_vars[] = { |
202 { ngx_string("pipe"), 1, ngx_http_log_pipe }, | |
581 | 203 { ngx_string("time_local"), sizeof("28/Sep/1970:12:00:00 +0600") - 1, |
573 | 204 ngx_http_log_time }, |
3873 | 205 { ngx_string("time_iso8601"), sizeof("1970-09-28T12:00:00+06:00") - 1, |
206 ngx_http_log_iso8601 }, | |
573 | 207 { 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
|
208 { ngx_string("request_time"), NGX_TIME_T_LEN + 4, |
6e2216ad2c87
$request_time has millisecond precision
Igor Sysoev <igor@sysoev.ru>
parents:
1161
diff
changeset
|
209 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
|
210 { ngx_string("status"), NGX_INT_T_LEN, ngx_http_log_status }, |
573 | 211 { ngx_string("bytes_sent"), NGX_OFF_T_LEN, ngx_http_log_bytes_sent }, |
577 | 212 { ngx_string("body_bytes_sent"), NGX_OFF_T_LEN, |
213 ngx_http_log_body_bytes_sent }, | |
573 | 214 { ngx_string("request_length"), NGX_SIZE_T_LEN, |
215 ngx_http_log_request_length }, | |
216 | |
217 { ngx_null_string, 0, NULL } | |
218 }; | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
219 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
220 |
4759
4c36e15651f7
Fixed compilation with -Wmissing-prototypes.
Ruslan Ermilov <ru@nginx.com>
parents:
4685
diff
changeset
|
221 static ngx_int_t |
497 | 222 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
|
223 { |
290
87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
282
diff
changeset
|
224 u_char *line, *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
|
225 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
|
226 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
|
227 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
|
228 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
|
229 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
|
230 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
|
231 |
210
00cafae0bdf1
nginx-0.0.1-2003-12-14-23:10:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
232 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
|
233 "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
|
234 |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
235 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
|
236 |
427
0d08eabe5c7b
nginx-0.0.10-2004-09-15-20:00:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
237 if (lcf->off) { |
0d08eabe5c7b
nginx-0.0.10-2004-09-15-20:00:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
238 return NGX_OK; |
0d08eabe5c7b
nginx-0.0.10-2004-09-15-20:00:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
239 } |
0d08eabe5c7b
nginx-0.0.10-2004-09-15-20:00:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
240 |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
241 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
|
242 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
|
243 |
633 | 244 if (ngx_time() == log[l].disk_full_time) { |
245 | |
246 /* | |
1071
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
247 * on FreeBSD writing to a full filesystem with enabled softupdates |
633 | 248 * 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
|
249 * filesystem, so we skip writing to a log for one second |
633 | 250 */ |
251 | |
252 continue; | |
253 } | |
254 | |
2261 | 255 ngx_http_script_flush_no_cacheable_variables(r, log[l].format->flushes); |
256 | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
257 len = 0; |
2261 | 258 op = log[l].format->ops->elts; |
259 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
|
260 if (op[i].len == 0) { |
479 | 261 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
|
262 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
263 } else { |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
264 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
|
265 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
266 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
267 |
571 | 268 len += NGX_LINEFEED_SIZE; |
269 | |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
270 buffer = log[l].file ? log[l].file->data : NULL; |
571 | 271 |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
272 if (buffer) { |
571 | 273 |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
274 if (len > (size_t) (buffer->last - buffer->pos)) { |
571 | 275 |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
276 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
|
277 buffer->pos - buffer->start); |
571 | 278 |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
279 buffer->pos = buffer->start; |
571 | 280 } |
281 | |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
282 if (len <= (size_t) (buffer->last - buffer->pos)) { |
571 | 283 |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
284 p = buffer->pos; |
571 | 285 |
2261 | 286 for (i = 0; i < log[l].format->ops->nelts; i++) { |
571 | 287 p = op[i].run(r, p, &op[i]); |
288 } | |
289 | |
290 ngx_linefeed(p); | |
291 | |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
292 buffer->pos = p; |
571 | 293 |
294 continue; | |
295 } | |
296 } | |
26
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
297 |
2049 | 298 line = ngx_pnalloc(r->pool, len); |
501 | 299 if (line == NULL) { |
473 | 300 return NGX_ERROR; |
301 } | |
302 | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
303 p = line; |
26
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
304 |
2261 | 305 for (i = 0; i < log[l].format->ops->nelts; i++) { |
479 | 306 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
|
307 } |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
308 |
571 | 309 ngx_linefeed(p); |
310 | |
1071
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
311 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
|
312 } |
26
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
313 |
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
314 return NGX_OK; |
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
315 } |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
316 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
317 |
1071
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
318 static void |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
319 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
|
320 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
|
321 { |
2072 | 322 u_char *name; |
323 time_t now; | |
324 ssize_t n; | |
325 ngx_err_t err; | |
1071
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
326 |
2072 | 327 if (log->script == NULL) { |
328 name = log->file->name.data; | |
329 n = ngx_write_fd(log->file->fd, buf, len); | |
330 | |
331 } else { | |
332 name = NULL; | |
333 n = ngx_http_log_script_write(r, log->script, &name, buf, len); | |
334 } | |
1071
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
335 |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
336 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
|
337 return; |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
338 } |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
339 |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
340 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
|
341 |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
342 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
|
343 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
|
344 |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
345 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
|
346 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
|
347 } |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
348 |
1161
6002e0253221
use 60 seconds interval but not 61 seconds
Igor Sysoev <igor@sysoev.ru>
parents:
1074
diff
changeset
|
349 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
|
350 ngx_log_error(NGX_LOG_ALERT, r->connection->log, err, |
2072 | 351 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
|
352 |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
353 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
|
354 } |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
355 |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
356 return; |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
357 } |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
358 |
1161
6002e0253221
use 60 seconds interval but not 61 seconds
Igor Sysoev <igor@sysoev.ru>
parents:
1074
diff
changeset
|
359 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
|
360 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, |
2072 | 361 ngx_write_fd_n " to \"%s\" was incomplete: %z of %uz", |
362 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
|
363 |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
364 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
|
365 } |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
366 } |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
367 |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
368 |
2072 | 369 static ssize_t |
370 ngx_http_log_script_write(ngx_http_request_t *r, ngx_http_log_script_t *script, | |
371 u_char **name, u_char *buf, size_t len) | |
372 { | |
373 size_t root; | |
374 ssize_t n; | |
375 ngx_str_t log, path; | |
376 ngx_open_file_info_t of; | |
377 ngx_http_log_loc_conf_t *llcf; | |
378 ngx_http_core_loc_conf_t *clcf; | |
379 | |
4478
08713bac87fc
Support for disable_symlinks in various modules.
Andrey Belov <defan@nginx.com>
parents:
4474
diff
changeset
|
380 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
|
381 |
2087
c8039b26a949
always test root existence for access_log with variables
Igor Sysoev <igor@sysoev.ru>
parents:
2080
diff
changeset
|
382 if (!r->root_tested) { |
2072 | 383 |
4499
778ef9c3fd2d
Fixed spelling in single-line comments.
Ruslan Ermilov <ru@nginx.com>
parents:
4494
diff
changeset
|
384 /* test root directory existence */ |
2072 | 385 |
386 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
|
387 /* simulate successful logging */ |
2072 | 388 return len; |
389 } | |
390 | |
391 path.data[root] = '\0'; | |
392 | |
393 ngx_memzero(&of, sizeof(ngx_open_file_info_t)); | |
394 | |
395 of.valid = clcf->open_file_cache_valid; | |
396 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
|
397 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
|
398 of.test_only = 1; |
2072 | 399 of.errors = clcf->open_file_cache_errors; |
400 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
|
401 |
13e09cf11d4e
Disable symlinks: initialization of the "disable_symlinks" field in
Valentin Bartenev <vbart@nginx.com>
parents:
4478
diff
changeset
|
402 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
|
403 /* simulate successful logging */ |
13e09cf11d4e
Disable symlinks: initialization of the "disable_symlinks" field in
Valentin Bartenev <vbart@nginx.com>
parents:
4478
diff
changeset
|
404 return len; |
13e09cf11d4e
Disable symlinks: initialization of the "disable_symlinks" field in
Valentin Bartenev <vbart@nginx.com>
parents:
4478
diff
changeset
|
405 } |
2072 | 406 |
407 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
|
408 != NGX_OK) |
2072 | 409 { |
2087
c8039b26a949
always test root existence for access_log with variables
Igor Sysoev <igor@sysoev.ru>
parents:
2080
diff
changeset
|
410 if (of.err == 0) { |
4499
778ef9c3fd2d
Fixed spelling in single-line comments.
Ruslan Ermilov <ru@nginx.com>
parents:
4494
diff
changeset
|
411 /* simulate successful logging */ |
2087
c8039b26a949
always test root existence for access_log with variables
Igor Sysoev <igor@sysoev.ru>
parents:
2080
diff
changeset
|
412 return len; |
c8039b26a949
always test root existence for access_log with variables
Igor Sysoev <igor@sysoev.ru>
parents:
2080
diff
changeset
|
413 } |
c8039b26a949
always test root existence for access_log with variables
Igor Sysoev <igor@sysoev.ru>
parents:
2080
diff
changeset
|
414 |
c8039b26a949
always test root existence for access_log with variables
Igor Sysoev <igor@sysoev.ru>
parents:
2080
diff
changeset
|
415 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
|
416 "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
|
417 |
4499
778ef9c3fd2d
Fixed spelling in single-line comments.
Ruslan Ermilov <ru@nginx.com>
parents:
4494
diff
changeset
|
418 /* simulate successful logging */ |
2087
c8039b26a949
always test root existence for access_log with variables
Igor Sysoev <igor@sysoev.ru>
parents:
2080
diff
changeset
|
419 return len; |
c8039b26a949
always test root existence for access_log with variables
Igor Sysoev <igor@sysoev.ru>
parents:
2080
diff
changeset
|
420 } |
c8039b26a949
always test root existence for access_log with variables
Igor Sysoev <igor@sysoev.ru>
parents:
2080
diff
changeset
|
421 |
c8039b26a949
always test root existence for access_log with variables
Igor Sysoev <igor@sysoev.ru>
parents:
2080
diff
changeset
|
422 if (!of.is_dir) { |
c8039b26a949
always test root existence for access_log with variables
Igor Sysoev <igor@sysoev.ru>
parents:
2080
diff
changeset
|
423 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
|
424 "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
|
425 |
4499
778ef9c3fd2d
Fixed spelling in single-line comments.
Ruslan Ermilov <ru@nginx.com>
parents:
4494
diff
changeset
|
426 /* simulate successful logging */ |
2072 | 427 return len; |
428 } | |
429 } | |
430 | |
431 if (ngx_http_script_run(r, &log, script->lengths->elts, 1, | |
432 script->values->elts) | |
433 == NULL) | |
434 { | |
4499
778ef9c3fd2d
Fixed spelling in single-line comments.
Ruslan Ermilov <ru@nginx.com>
parents:
4494
diff
changeset
|
435 /* simulate successful logging */ |
2072 | 436 return len; |
437 } | |
438 | |
439 log.data[log.len - 1] = '\0'; | |
440 *name = log.data; | |
441 | |
442 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
443 "http log \"%s\"", log.data); | |
444 | |
445 llcf = ngx_http_get_module_loc_conf(r, ngx_http_log_module); | |
446 | |
447 ngx_memzero(&of, sizeof(ngx_open_file_info_t)); | |
448 | |
449 of.log = 1; | |
450 of.valid = llcf->open_file_cache_valid; | |
451 of.min_uses = llcf->open_file_cache_min_uses; | |
2277 | 452 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
|
453 |
13e09cf11d4e
Disable symlinks: initialization of the "disable_symlinks" field in
Valentin Bartenev <vbart@nginx.com>
parents:
4478
diff
changeset
|
454 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
|
455 /* simulate successful logging */ |
13e09cf11d4e
Disable symlinks: initialization of the "disable_symlinks" field in
Valentin Bartenev <vbart@nginx.com>
parents:
4478
diff
changeset
|
456 return len; |
13e09cf11d4e
Disable symlinks: initialization of the "disable_symlinks" field in
Valentin Bartenev <vbart@nginx.com>
parents:
4478
diff
changeset
|
457 } |
2072 | 458 |
459 if (ngx_open_cached_file(llcf->open_file_cache, &log, &of, r->pool) | |
460 != NGX_OK) | |
461 { | |
462 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
|
463 "%s \"%s\" failed", of.failed, log.data); |
4499
778ef9c3fd2d
Fixed spelling in single-line comments.
Ruslan Ermilov <ru@nginx.com>
parents:
4494
diff
changeset
|
464 /* simulate successful logging */ |
2077 | 465 return len; |
2072 | 466 } |
467 | |
468 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
469 "http log #%d", of.fd); | |
470 | |
471 n = ngx_write_fd(of.fd, buf, len); | |
472 | |
473 return n; | |
474 } | |
475 | |
476 | |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
477 static void |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
478 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
|
479 { |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
480 size_t len; |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
481 ssize_t n; |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
482 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
|
483 |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
484 buffer = file->data; |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
485 |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
486 len = buffer->pos - buffer->start; |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
487 |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
488 if (len == 0) { |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
489 return; |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
490 } |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
491 |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
492 n = ngx_write_fd(file->fd, buffer->start, len); |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
493 |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
494 if (n == -1) { |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
495 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
|
496 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
|
497 file->name.data); |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
498 |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
499 } 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
|
500 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
|
501 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
|
502 file->name.data, n, len); |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
503 } |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
504 |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
505 buffer->pos = buffer->start; |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
506 } |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
507 |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
508 |
497 | 509 static u_char * |
510 ngx_http_log_copy_short(ngx_http_request_t *r, u_char *buf, | |
511 ngx_http_log_op_t *op) | |
479 | 512 { |
513 size_t len; | |
514 uintptr_t data; | |
515 | |
516 len = op->len; | |
517 data = op->data; | |
518 | |
519 while (len--) { | |
520 *buf++ = (u_char) (data & 0xff); | |
521 data >>= 8; | |
522 } | |
523 | |
524 return buf; | |
525 } | |
526 | |
527 | |
497 | 528 static u_char * |
529 ngx_http_log_copy_long(ngx_http_request_t *r, u_char *buf, | |
530 ngx_http_log_op_t *op) | |
479 | 531 { |
532 return ngx_cpymem(buf, (u_char *) op->data, op->len); | |
533 } | |
534 | |
535 | |
497 | 536 static u_char * |
537 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
|
538 { |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
539 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
|
540 *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
|
541 } else { |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
542 *buf = '.'; |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
543 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
544 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
545 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
|
546 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
547 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
548 |
497 | 549 static u_char * |
550 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
|
551 { |
178
a8ff48d26cca
nginx-0.0.1-2003-11-11-00:09:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
177
diff
changeset
|
552 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
|
553 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
|
554 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
555 |
3873 | 556 static u_char * |
557 ngx_http_log_iso8601(ngx_http_request_t *r, u_char *buf, ngx_http_log_op_t *op) | |
558 { | |
559 return ngx_cpymem(buf, ngx_cached_http_log_iso8601.data, | |
560 ngx_cached_http_log_iso8601.len); | |
561 } | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
562 |
497 | 563 static u_char * |
564 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
|
565 { |
563 | 566 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
|
567 |
563 | 568 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
|
569 |
563 | 570 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
|
571 } |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
393
diff
changeset
|
572 |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
393
diff
changeset
|
573 |
497 | 574 static u_char * |
575 ngx_http_log_request_time(ngx_http_request_t *r, u_char *buf, | |
576 ngx_http_log_op_t *op) | |
577 { | |
1179
6e2216ad2c87
$request_time has millisecond precision
Igor Sysoev <igor@sysoev.ru>
parents:
1161
diff
changeset
|
578 ngx_time_t *tp; |
6e2216ad2c87
$request_time has millisecond precision
Igor Sysoev <igor@sysoev.ru>
parents:
1161
diff
changeset
|
579 ngx_msec_int_t ms; |
6e2216ad2c87
$request_time has millisecond precision
Igor Sysoev <igor@sysoev.ru>
parents:
1161
diff
changeset
|
580 |
6e2216ad2c87
$request_time has millisecond precision
Igor Sysoev <igor@sysoev.ru>
parents:
1161
diff
changeset
|
581 tp = ngx_timeofday(); |
497 | 582 |
1640 | 583 ms = (ngx_msec_int_t) |
584 ((tp->sec - r->start_sec) * 1000 + (tp->msec - r->start_msec)); | |
3515 | 585 ms = ngx_max(ms, 0); |
497 | 586 |
1179
6e2216ad2c87
$request_time has millisecond precision
Igor Sysoev <igor@sysoev.ru>
parents:
1161
diff
changeset
|
587 return ngx_sprintf(buf, "%T.%03M", ms / 1000, ms % 1000); |
497 | 588 } |
589 | |
590 | |
591 static u_char * | |
592 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
|
593 { |
3370
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
594 ngx_uint_t status; |
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
595 |
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
596 if (r->err_status) { |
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
597 status = r->err_status; |
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
598 |
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
599 } 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
|
600 status = r->headers_out.status; |
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
601 |
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
602 } else if (r->http_version == NGX_HTTP_VERSION_9) { |
4685
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4637
diff
changeset
|
603 status = 9; |
3370
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
604 |
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
605 } else { |
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
606 status = 0; |
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
607 } |
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
608 |
4637
668ab1a21327
Zero padded the returned and logged HTTP status code, and fixed possible
Ruslan Ermilov <ru@nginx.com>
parents:
4539
diff
changeset
|
609 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
|
610 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
611 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
612 |
497 | 613 static u_char * |
573 | 614 ngx_http_log_bytes_sent(ngx_http_request_t *r, u_char *buf, |
615 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
|
616 { |
455 | 617 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
|
618 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
619 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
620 |
1271 | 621 /* |
622 * although there is a real $body_bytes_sent variable, | |
623 * this log operation code function is more optimized for logging | |
624 */ | |
625 | |
497 | 626 static u_char * |
577 | 627 ngx_http_log_body_bytes_sent(ngx_http_request_t *r, u_char *buf, |
497 | 628 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
|
629 { |
497 | 630 off_t length; |
631 | |
632 length = r->connection->sent - r->header_size; | |
633 | |
634 if (length > 0) { | |
635 return ngx_sprintf(buf, "%O", length); | |
636 } | |
637 | |
638 *buf = '0'; | |
639 | |
640 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
|
641 } |
00cafae0bdf1
nginx-0.0.1-2003-12-14-23:10:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
642 |
00cafae0bdf1
nginx-0.0.1-2003-12-14-23:10:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
643 |
497 | 644 static u_char * |
645 ngx_http_log_request_length(ngx_http_request_t *r, u_char *buf, | |
646 ngx_http_log_op_t *op) | |
475 | 647 { |
663 | 648 return ngx_sprintf(buf, "%O", r->request_length); |
475 | 649 } |
650 | |
651 | |
497 | 652 static ngx_int_t |
501 | 653 ngx_http_log_variable_compile(ngx_conf_t *cf, ngx_http_log_op_t *op, |
654 ngx_str_t *value) | |
655 { | |
509 | 656 ngx_int_t index; |
501 | 657 |
509 | 658 index = ngx_http_get_variable_index(cf, value); |
659 if (index == NGX_ERROR) { | |
501 | 660 return NGX_ERROR; |
661 } | |
662 | |
663 op->len = 0; | |
664 op->getlen = ngx_http_log_variable_getlen; | |
665 op->run = ngx_http_log_variable; | |
509 | 666 op->data = index; |
501 | 667 |
668 return NGX_OK; | |
669 } | |
670 | |
671 | |
672 static size_t | |
673 ngx_http_log_variable_getlen(ngx_http_request_t *r, uintptr_t data) | |
674 { | |
2008
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
675 uintptr_t len; |
501 | 676 ngx_http_variable_value_t *value; |
677 | |
678 value = ngx_http_get_indexed_variable(r, data); | |
679 | |
573 | 680 if (value == NULL || value->not_found) { |
501 | 681 return 1; |
682 } | |
683 | |
2008
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
684 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
|
685 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
686 value->escape = len ? 1 : 0; |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
687 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
688 return value->len + len * 3; |
501 | 689 } |
690 | |
691 | |
692 static u_char * | |
693 ngx_http_log_variable(ngx_http_request_t *r, u_char *buf, ngx_http_log_op_t *op) | |
694 { | |
695 ngx_http_variable_value_t *value; | |
696 | |
697 value = ngx_http_get_indexed_variable(r, op->data); | |
698 | |
573 | 699 if (value == NULL || value->not_found) { |
501 | 700 *buf = '-'; |
701 return buf + 1; | |
702 } | |
703 | |
2008
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
704 if (value->escape == 0) { |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
705 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
|
706 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
707 } else { |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
708 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
|
709 } |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
710 } |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
711 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
712 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
713 static uintptr_t |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
714 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
|
715 { |
3275 | 716 ngx_uint_t n; |
2008
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
717 static u_char hex[] = "0123456789ABCDEF"; |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
718 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
719 static uint32_t escape[] = { |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
720 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
|
721 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
722 /* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */ |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
723 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
|
724 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
725 /* _^]\ [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
|
726 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
|
727 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
728 /* ~}| {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
|
729 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
|
730 |
4191
08d8af70760c
Improved access log escaping to better protect other software.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4133
diff
changeset
|
731 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
|
732 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
|
733 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
|
734 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
|
735 }; |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
736 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
737 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
738 if (dst == NULL) { |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
739 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
740 /* 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
|
741 |
3115 | 742 n = 0; |
2008
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
743 |
3275 | 744 while (size) { |
2008
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
745 if (escape[*src >> 5] & (1 << (*src & 0x1f))) { |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
746 n++; |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
747 } |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
748 src++; |
3275 | 749 size--; |
2008
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
750 } |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
751 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
752 return (uintptr_t) n; |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
753 } |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
754 |
3275 | 755 while (size) { |
2008
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
756 if (escape[*src >> 5] & (1 << (*src & 0x1f))) { |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
757 *dst++ = '\\'; |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
758 *dst++ = 'x'; |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
759 *dst++ = hex[*src >> 4]; |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
760 *dst++ = hex[*src & 0xf]; |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
761 src++; |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
762 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
763 } else { |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
764 *dst++ = *src++; |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
765 } |
3275 | 766 size--; |
2008
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
767 } |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
768 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
769 return (uintptr_t) dst; |
501 | 770 } |
771 | |
772 | |
497 | 773 static void * |
774 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
|
775 { |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
776 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
|
777 |
573 | 778 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
|
779 |
501 | 780 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_log_main_conf_t)); |
781 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
|
782 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
|
783 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
784 |
497 | 785 if (ngx_array_init(&conf->formats, cf->pool, 4, sizeof(ngx_http_log_fmt_t)) |
573 | 786 != NGX_OK) |
497 | 787 { |
2912
c7d57b539248
return NULL instead of NGX_CONF_ERROR on a create conf failure
Igor Sysoev <igor@sysoev.ru>
parents:
2756
diff
changeset
|
788 return NULL; |
497 | 789 } |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
790 |
573 | 791 fmt = ngx_array_push(&conf->formats); |
792 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
|
793 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
|
794 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
795 |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
796 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
|
797 |
2261 | 798 fmt->flushes = NULL; |
799 | |
573 | 800 fmt->ops = ngx_array_create(cf->pool, 16, sizeof(ngx_http_log_op_t)); |
801 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
|
802 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
|
803 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
804 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
805 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
|
806 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
807 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
808 |
497 | 809 static void * |
810 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
|
811 { |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
812 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
|
813 |
501 | 814 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_log_loc_conf_t)); |
815 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
|
816 return NULL; |
427
0d08eabe5c7b
nginx-0.0.10-2004-09-15-20:00:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
817 } |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
818 |
2072 | 819 conf->open_file_cache = NGX_CONF_UNSET_PTR; |
820 | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
821 return conf; |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
822 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
823 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
824 |
497 | 825 static char * |
826 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
|
827 { |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
828 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
|
829 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
|
830 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
831 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
|
832 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
|
833 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
|
834 |
2072 | 835 if (conf->open_file_cache == NGX_CONF_UNSET_PTR) { |
836 | |
837 conf->open_file_cache = prev->open_file_cache; | |
838 conf->open_file_cache_valid = prev->open_file_cache_valid; | |
839 conf->open_file_cache_min_uses = prev->open_file_cache_min_uses; | |
840 | |
841 if (conf->open_file_cache == NGX_CONF_UNSET_PTR) { | |
842 conf->open_file_cache = NULL; | |
843 } | |
844 } | |
845 | |
1074 | 846 if (conf->logs || conf->off) { |
847 return NGX_CONF_OK; | |
848 } | |
427
0d08eabe5c7b
nginx-0.0.10-2004-09-15-20:00:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
849 |
2078
9acbc5e7bcbd
fix variable access_log merging
Igor Sysoev <igor@sysoev.ru>
parents:
2077
diff
changeset
|
850 conf->logs = prev->logs; |
9acbc5e7bcbd
fix variable access_log merging
Igor Sysoev <igor@sysoev.ru>
parents:
2077
diff
changeset
|
851 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
|
852 |
1074 | 853 if (conf->logs || conf->off) { |
854 return NGX_CONF_OK; | |
855 } | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
856 |
1074 | 857 conf->logs = ngx_array_create(cf->pool, 2, sizeof(ngx_http_log_t)); |
858 if (conf->logs == NULL) { | |
859 return NGX_CONF_ERROR; | |
860 } | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
861 |
1074 | 862 log = ngx_array_push(conf->logs); |
863 if (log == NULL) { | |
864 return NGX_CONF_ERROR; | |
865 } | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
866 |
1074 | 867 log->file = ngx_conf_open_file(cf->cycle, &ngx_http_access_log); |
868 if (log->file == NULL) { | |
869 return NGX_CONF_ERROR; | |
870 } | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
871 |
2080
a24c7009de0b
NULL script in default access_log
Igor Sysoev <igor@sysoev.ru>
parents:
2078
diff
changeset
|
872 log->script = NULL; |
1074 | 873 log->disk_full_time = 0; |
874 log->error_log_time = 0; | |
427
0d08eabe5c7b
nginx-0.0.10-2004-09-15-20:00:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
875 |
1074 | 876 lmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_log_module); |
877 fmt = lmcf->formats.elts; | |
878 | |
879 /* the default "combined" format */ | |
2261 | 880 log->format = &fmt[0]; |
1074 | 881 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
|
882 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
883 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
|
884 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
885 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
886 |
497 | 887 static char * |
888 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
|
889 { |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
890 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
|
891 |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
892 ssize_t size; |
2072 | 893 ngx_uint_t i, n; |
894 ngx_str_t *value, name; | |
895 ngx_http_log_t *log; | |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
896 ngx_http_log_buf_t *buffer; |
2072 | 897 ngx_http_log_fmt_t *fmt; |
898 ngx_http_log_main_conf_t *lmcf; | |
899 ngx_http_script_compile_t sc; | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
900 |
427
0d08eabe5c7b
nginx-0.0.10-2004-09-15-20:00:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
901 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
|
902 |
0d08eabe5c7b
nginx-0.0.10-2004-09-15-20:00:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
903 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
|
904 llcf->off = 1; |
3038
cd8738e76610
strict testing "access_log off"
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
905 if (cf->args->nelts == 2) { |
cd8738e76610
strict testing "access_log off"
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
906 return NGX_CONF_OK; |
cd8738e76610
strict testing "access_log off"
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
907 } |
cd8738e76610
strict testing "access_log off"
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
908 |
cd8738e76610
strict testing "access_log off"
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
909 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
cd8738e76610
strict testing "access_log off"
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
910 "invalid parameter \"%V\"", &value[2]); |
cd8738e76610
strict testing "access_log off"
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
911 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
|
912 } |
0d08eabe5c7b
nginx-0.0.10-2004-09-15-20:00:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
913 |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
914 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
|
915 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
|
916 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
|
917 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
|
918 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
919 } |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
920 |
393
5659d773cfa8
nginx-0.0.7-2004-07-15-20:35:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
356
diff
changeset
|
921 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
|
922 |
501 | 923 log = ngx_array_push(llcf->logs); |
924 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
|
925 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
|
926 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
927 |
2072 | 928 ngx_memzero(log, sizeof(ngx_http_log_t)); |
929 | |
930 n = ngx_http_script_variables_count(&value[1]); | |
931 | |
932 if (n == 0) { | |
933 log->file = ngx_conf_open_file(cf->cycle, &value[1]); | |
934 if (log->file == NULL) { | |
935 return NGX_CONF_ERROR; | |
936 } | |
937 | |
938 } else { | |
2536
a6d6d762c554
small optimization: " == NGX_ERROR" > " != NGX_OK"
Igor Sysoev <igor@sysoev.ru>
parents:
2277
diff
changeset
|
939 if (ngx_conf_full_name(cf->cycle, &value[1], 0) != NGX_OK) { |
2072 | 940 return NGX_CONF_ERROR; |
941 } | |
942 | |
943 log->script = ngx_pcalloc(cf->pool, sizeof(ngx_http_log_script_t)); | |
944 if (log->script == NULL) { | |
945 return NGX_CONF_ERROR; | |
946 } | |
947 | |
948 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t)); | |
949 | |
950 sc.cf = cf; | |
951 sc.source = &value[1]; | |
952 sc.lengths = &log->script->lengths; | |
953 sc.values = &log->script->values; | |
954 sc.variables = n; | |
955 sc.complete_lengths = 1; | |
956 sc.complete_values = 1; | |
957 | |
958 if (ngx_http_script_compile(&sc) != NGX_OK) { | |
959 return NGX_CONF_ERROR; | |
960 } | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
961 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
962 |
571 | 963 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
|
964 name = value[2]; |
581 | 965 |
966 if (ngx_strcmp(name.data, "combined") == 0) { | |
967 lmcf->combined_used = 1; | |
968 } | |
969 | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
970 } else { |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
971 ngx_str_set(&name, "combined"); |
573 | 972 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
|
973 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
974 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
975 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
|
976 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
|
977 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
|
978 && 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
|
979 { |
2261 | 980 log->format = &fmt[i]; |
571 | 981 goto 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
|
982 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
983 } |
100
7ebc8b7fb816
nginx-0.0.1-2003-06-03-19:42:58 import
Igor Sysoev <igor@sysoev.ru>
parents:
99
diff
changeset
|
984 |
487 | 985 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
986 "unknown log format \"%V\"", &name); | |
571 | 987 return NGX_CONF_ERROR; |
487 | 988 |
571 | 989 buffer: |
990 | |
991 if (cf->args->nelts == 4) { | |
992 if (ngx_strncmp(value[3].data, "buffer=", 7) != 0) { | |
993 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
994 "invalid parameter \"%V\"", &value[3]); | |
995 return NGX_CONF_ERROR; | |
996 } | |
997 | |
2072 | 998 if (log->script) { |
999 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
|
1000 "buffered logs cannot have variables in name"); |
2072 | 1001 return NGX_CONF_ERROR; |
1002 } | |
1003 | |
571 | 1004 name.len = value[3].len - 7; |
1005 name.data = value[3].data + 7; | |
1006 | |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1007 size = ngx_parse_size(&name); |
571 | 1008 |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1009 if (size == NGX_ERROR) { |
571 | 1010 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
4327
73d37e1ccb91
- Improved error message when parsing of the "buffer" parameter of the
Ruslan Ermilov <ru@nginx.com>
parents:
4191
diff
changeset
|
1011 "invalid buffer value \"%V\"", &name); |
571 | 1012 return NGX_CONF_ERROR; |
1013 } | |
1014 | |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1015 if (log->file->data) { |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1016 buffer = log->file->data; |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1017 |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1018 if (buffer->last - buffer->start != size) { |
4984
7737f0d788c1
Access log: fixed redundant buffer reallocation.
Valentin Bartenev <vbart@nginx.com>
parents:
4893
diff
changeset
|
1019 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
|
1020 "access_log \"%V\" already defined " |
7737f0d788c1
Access log: fixed redundant buffer reallocation.
Valentin Bartenev <vbart@nginx.com>
parents:
4893
diff
changeset
|
1021 "with different buffer size", &value[1]); |
7737f0d788c1
Access log: fixed redundant buffer reallocation.
Valentin Bartenev <vbart@nginx.com>
parents:
4893
diff
changeset
|
1022 return NGX_CONF_ERROR; |
7737f0d788c1
Access log: fixed redundant buffer reallocation.
Valentin Bartenev <vbart@nginx.com>
parents:
4893
diff
changeset
|
1023 } |
7737f0d788c1
Access log: fixed redundant buffer reallocation.
Valentin Bartenev <vbart@nginx.com>
parents:
4893
diff
changeset
|
1024 |
7737f0d788c1
Access log: fixed redundant buffer reallocation.
Valentin Bartenev <vbart@nginx.com>
parents:
4893
diff
changeset
|
1025 return NGX_CONF_OK; |
571 | 1026 } |
1027 | |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1028 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
|
1029 if (buffer == NULL) { |
571 | 1030 return NGX_CONF_ERROR; |
1031 } | |
1032 | |
4985
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1033 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
|
1034 if (buffer->start == NULL) { |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1035 return NGX_CONF_ERROR; |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1036 } |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1037 |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1038 buffer->pos = buffer->start; |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1039 buffer->last = buffer->start + size; |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1040 |
a0599b56e748
Reopening log files code moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
4984
diff
changeset
|
1041 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
|
1042 log->file->data = buffer; |
571 | 1043 } |
1044 | |
1045 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
|
1046 } |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1047 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1048 |
497 | 1049 static char * |
1050 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
|
1051 { |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1052 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
|
1053 |
573 | 1054 ngx_str_t *value; |
1055 ngx_uint_t i; | |
1056 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
|
1057 |
4327
73d37e1ccb91
- Improved error message when parsing of the "buffer" parameter of the
Ruslan Ermilov <ru@nginx.com>
parents:
4191
diff
changeset
|
1058 if (cf->cmd_type != NGX_HTTP_MAIN_CONF) { |
73d37e1ccb91
- Improved error message when parsing of the "buffer" parameter of the
Ruslan Ermilov <ru@nginx.com>
parents:
4191
diff
changeset
|
1059 ngx_conf_log_error(NGX_LOG_WARN, cf, 0, |
73d37e1ccb91
- Improved error message when parsing of the "buffer" parameter of the
Ruslan Ermilov <ru@nginx.com>
parents:
4191
diff
changeset
|
1060 "the \"log_format\" directive may be used " |
73d37e1ccb91
- Improved error message when parsing of the "buffer" parameter of the
Ruslan Ermilov <ru@nginx.com>
parents:
4191
diff
changeset
|
1061 "only on \"http\" level"); |
73d37e1ccb91
- Improved error message when parsing of the "buffer" parameter of the
Ruslan Ermilov <ru@nginx.com>
parents:
4191
diff
changeset
|
1062 } |
73d37e1ccb91
- Improved error message when parsing of the "buffer" parameter of the
Ruslan Ermilov <ru@nginx.com>
parents:
4191
diff
changeset
|
1063 |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1064 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
|
1065 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1066 fmt = lmcf->formats.elts; |
573 | 1067 for (i = 0; i < lmcf->formats.nelts; i++) { |
1068 if (fmt[i].name.len == value[1].len | |
1069 && 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
|
1070 { |
2036 | 1071 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
1072 "duplicate \"log_format\" name \"%V\"", | |
1073 &value[1]); | |
1074 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
|
1075 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1076 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1077 |
501 | 1078 fmt = ngx_array_push(&lmcf->formats); |
1079 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
|
1080 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
|
1081 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1082 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1083 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
|
1084 |
2261 | 1085 fmt->flushes = ngx_array_create(cf->pool, 4, sizeof(ngx_int_t)); |
1086 if (fmt->flushes == NULL) { | |
1087 return NGX_CONF_ERROR; | |
1088 } | |
1089 | |
573 | 1090 fmt->ops = ngx_array_create(cf->pool, 16, sizeof(ngx_http_log_op_t)); |
501 | 1091 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
|
1092 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
|
1093 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1094 |
2261 | 1095 return ngx_http_log_compile_format(cf, fmt->flushes, fmt->ops, cf->args, 2); |
573 | 1096 } |
1097 | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1098 |
573 | 1099 static char * |
2261 | 1100 ngx_http_log_compile_format(ngx_conf_t *cf, ngx_array_t *flushes, |
1101 ngx_array_t *ops, ngx_array_t *args, ngx_uint_t s) | |
573 | 1102 { |
880 | 1103 u_char *data, *p, ch; |
1104 size_t i, len; | |
1105 ngx_str_t *value, var; | |
2261 | 1106 ngx_int_t *flush; |
880 | 1107 ngx_uint_t bracket; |
1108 ngx_http_log_op_t *op; | |
1109 ngx_http_log_var_t *v; | |
573 | 1110 |
1111 value = args->elts; | |
1112 | |
1113 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
|
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 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
|
1116 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1117 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
|
1118 |
573 | 1119 op = ngx_array_push(ops); |
501 | 1120 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
|
1121 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
|
1122 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1123 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1124 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
|
1125 |
880 | 1126 if (value[s].data[i] == '$') { |
569 | 1127 |
1128 if (++i == value[s].len) { | |
1129 goto invalid; | |
1130 } | |
1131 | |
1132 if (value[s].data[i] == '{') { | |
1133 bracket = 1; | |
1134 | |
1135 if (++i == value[s].len) { | |
1136 goto invalid; | |
1137 } | |
1138 | |
1139 var.data = &value[s].data[i]; | |
1140 | |
1141 } else { | |
1142 bracket = 0; | |
1143 var.data = &value[s].data[i]; | |
1144 } | |
1145 | |
1146 for (var.len = 0; i < value[s].len; i++, var.len++) { | |
1147 ch = value[s].data[i]; | |
1148 | |
1149 if (ch == '}' && bracket) { | |
1150 i++; | |
1151 bracket = 0; | |
1152 break; | |
1153 } | |
1154 | |
1155 if ((ch >= 'A' && ch <= 'Z') | |
1156 || (ch >= 'a' && ch <= 'z') | |
1157 || (ch >= '0' && ch <= '9') | |
1158 || ch == '_') | |
1159 { | |
1160 continue; | |
1161 } | |
1162 | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1163 break; |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1164 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1165 |
569 | 1166 if (bracket) { |
1167 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1168 "the closing bracket in \"%V\" " | |
1169 "variable is missing", &var); | |
1170 return NGX_CONF_ERROR; | |
1171 } | |
1172 | |
1173 if (var.len == 0) { | |
1174 goto invalid; | |
1175 } | |
1176 | |
573 | 1177 for (v = ngx_http_log_vars; v->name.len; v++) { |
1178 | |
1179 if (v->name.len == var.len | |
1180 && ngx_strncmp(v->name.data, var.data, var.len) == 0) | |
1181 { | |
1182 op->len = v->len; | |
1183 op->getlen = NULL; | |
1184 op->run = v->run; | |
1185 op->data = 0; | |
1186 | |
1187 goto found; | |
1188 } | |
1189 } | |
1190 | |
569 | 1191 if (ngx_http_log_variable_compile(cf, op, &var) != NGX_OK) { |
1192 return NGX_CONF_ERROR; | |
1193 } | |
1194 | |
2261 | 1195 if (flushes) { |
1196 | |
1197 flush = ngx_array_push(flushes); | |
1198 if (flush == NULL) { | |
1199 return NGX_CONF_ERROR; | |
1200 } | |
1201 | |
1202 *flush = op->data; /* variable index */ | |
1203 } | |
1204 | |
573 | 1205 found: |
1206 | |
1207 continue; | |
1208 } | |
1209 | |
1210 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
|
1211 |
880 | 1212 while (i < value[s].len && value[s].data[i] != '$') { |
573 | 1213 i++; |
1214 } | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1215 |
573 | 1216 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
|
1217 |
573 | 1218 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
|
1219 |
573 | 1220 op->len = len; |
1221 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
|
1222 |
573 | 1223 if (len <= sizeof(uintptr_t)) { |
1224 op->run = ngx_http_log_copy_short; | |
1225 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
|
1226 |
573 | 1227 while (len--) { |
1228 op->data <<= 8; | |
1229 op->data |= data[len]; | |
1230 } | |
1231 | |
1232 } else { | |
1233 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
|
1234 |
2049 | 1235 p = ngx_pnalloc(cf->pool, len); |
573 | 1236 if (p == NULL) { |
1237 return NGX_CONF_ERROR; | |
1238 } | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1239 |
573 | 1240 ngx_memcpy(p, data, len); |
1241 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
|
1242 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1243 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1244 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1245 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1246 |
569 | 1247 return NGX_CONF_OK; |
1248 | |
1249 invalid: | |
1250 | |
1251 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "invalid parameter \"%s\"", data); | |
1252 | |
1253 return NGX_CONF_ERROR; | |
1254 } | |
1255 | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1256 |
2072 | 1257 static char * |
1258 ngx_http_log_open_file_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
1259 { | |
1260 ngx_http_log_loc_conf_t *llcf = conf; | |
1261 | |
1262 time_t inactive, valid; | |
1263 ngx_str_t *value, s; | |
1264 ngx_int_t max, min_uses; | |
1265 ngx_uint_t i; | |
1266 | |
1267 if (llcf->open_file_cache != NGX_CONF_UNSET_PTR) { | |
1268 return "is duplicate"; | |
1269 } | |
1270 | |
1271 value = cf->args->elts; | |
1272 | |
1273 max = 0; | |
1274 inactive = 10; | |
1275 valid = 60; | |
1276 min_uses = 1; | |
1277 | |
1278 for (i = 1; i < cf->args->nelts; i++) { | |
1279 | |
1280 if (ngx_strncmp(value[i].data, "max=", 4) == 0) { | |
1281 | |
1282 max = ngx_atoi(value[i].data + 4, value[i].len - 4); | |
1283 if (max == NGX_ERROR) { | |
1284 goto failed; | |
1285 } | |
1286 | |
1287 continue; | |
1288 } | |
1289 | |
1290 if (ngx_strncmp(value[i].data, "inactive=", 9) == 0) { | |
1291 | |
1292 s.len = value[i].len - 9; | |
1293 s.data = value[i].data + 9; | |
1294 | |
1295 inactive = ngx_parse_time(&s, 1); | |
4474 | 1296 if (inactive == (time_t) NGX_ERROR) { |
2072 | 1297 goto failed; |
1298 } | |
1299 | |
1300 continue; | |
1301 } | |
1302 | |
1303 if (ngx_strncmp(value[i].data, "min_uses=", 9) == 0) { | |
1304 | |
1305 min_uses = ngx_atoi(value[i].data + 9, value[i].len - 9); | |
1306 if (min_uses == NGX_ERROR) { | |
1307 goto failed; | |
1308 } | |
1309 | |
1310 continue; | |
1311 } | |
1312 | |
1313 if (ngx_strncmp(value[i].data, "valid=", 6) == 0) { | |
1314 | |
1315 s.len = value[i].len - 6; | |
1316 s.data = value[i].data + 6; | |
1317 | |
1318 valid = ngx_parse_time(&s, 1); | |
4474 | 1319 if (valid == (time_t) NGX_ERROR) { |
2072 | 1320 goto failed; |
1321 } | |
1322 | |
1323 continue; | |
1324 } | |
1325 | |
1326 if (ngx_strcmp(value[i].data, "off") == 0) { | |
1327 | |
1328 llcf->open_file_cache = NULL; | |
1329 | |
1330 continue; | |
1331 } | |
1332 | |
1333 failed: | |
1334 | |
1335 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1336 "invalid \"open_log_file_cache\" parameter \"%V\"", | |
1337 &value[i]); | |
1338 return NGX_CONF_ERROR; | |
1339 } | |
1340 | |
1341 if (llcf->open_file_cache == NULL) { | |
1342 return NGX_CONF_OK; | |
1343 } | |
1344 | |
1345 if (max == 0) { | |
1346 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1347 "\"open_log_file_cache\" must have \"max\" parameter"); | |
1348 return NGX_CONF_ERROR; | |
1349 } | |
1350 | |
1351 llcf->open_file_cache = ngx_open_file_cache_init(cf->pool, max, inactive); | |
1352 | |
1353 if (llcf->open_file_cache) { | |
1354 | |
1355 llcf->open_file_cache_valid = valid; | |
1356 llcf->open_file_cache_min_uses = min_uses; | |
1357 | |
1358 return NGX_CONF_OK; | |
1359 } | |
1360 | |
1361 return NGX_CONF_ERROR; | |
1362 } | |
1363 | |
1364 | |
569 | 1365 static ngx_int_t |
573 | 1366 ngx_http_log_init(ngx_conf_t *cf) |
569 | 1367 { |
573 | 1368 ngx_str_t *value; |
1369 ngx_array_t a; | |
581 | 1370 ngx_http_handler_pt *h; |
573 | 1371 ngx_http_log_fmt_t *fmt; |
1372 ngx_http_log_main_conf_t *lmcf; | |
569 | 1373 ngx_http_core_main_conf_t *cmcf; |
1374 | |
573 | 1375 lmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_log_module); |
1376 | |
1377 if (lmcf->combined_used) { | |
1378 if (ngx_array_init(&a, cf->pool, 1, sizeof(ngx_str_t)) != NGX_OK) { | |
1379 return NGX_ERROR; | |
1380 } | |
1381 | |
1382 value = ngx_array_push(&a); | |
1383 if (value == NULL) { | |
1384 return NGX_ERROR; | |
1385 } | |
1386 | |
1387 *value = ngx_http_combined_fmt; | |
1388 fmt = lmcf->formats.elts; | |
1389 | |
2261 | 1390 if (ngx_http_log_compile_format(cf, NULL, fmt->ops, &a, 0) |
573 | 1391 != NGX_CONF_OK) |
1392 { | |
1393 return NGX_ERROR; | |
1394 } | |
1395 } | |
1396 | |
1397 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module); | |
569 | 1398 |
581 | 1399 h = ngx_array_push(&cmcf->phases[NGX_HTTP_LOG_PHASE].handlers); |
1400 if (h == NULL) { | |
1401 return NGX_ERROR; | |
1402 } | |
1403 | |
1404 *h = ngx_http_log_handler; | |
569 | 1405 |
1406 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
|
1407 } |