Mercurial > hg > nginx
annotate src/http/modules/ngx_http_log_module.c @ 4727:1c7616100797 stable-1.2
Merge of r4688, r4689, r4706:
*) Mp4: fixed non-keyframe seeks in some cases (ticket #175).
Number of entries in stsc atom was wrong if we've added an entry to
split a chunk.
Additionally, there is no need to add an entry if we are going to split
last chunk in an entry, it's enough to update the entry we already have.
Previously new entry was added and old one was left as is, resulting in
incorrect entry with zero chunks which might confuse some software.
*) Mp4: fixed streaming if moov atom is at buffer edge.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 02 Jul 2012 16:56:53 +0000 |
parents | dad38cdaf496 |
children | 4c36e15651f7 |
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 { |
2072 | 44 ngx_array_t *lengths; |
45 ngx_array_t *values; | |
46 } ngx_http_log_script_t; | |
47 | |
48 | |
49 typedef struct { | |
573 | 50 ngx_open_file_t *file; |
2072 | 51 ngx_http_log_script_t *script; |
633 | 52 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
|
53 time_t error_log_time; |
2261 | 54 ngx_http_log_fmt_t *format; |
573 | 55 } ngx_http_log_t; |
56 | |
657 | 57 |
573 | 58 typedef struct { |
59 ngx_array_t *logs; /* array of ngx_http_log_t */ | |
2072 | 60 |
61 ngx_open_file_cache_t *open_file_cache; | |
62 time_t open_file_cache_valid; | |
63 ngx_uint_t open_file_cache_min_uses; | |
64 | |
573 | 65 ngx_uint_t off; /* unsigned off:1 */ |
66 } ngx_http_log_loc_conf_t; | |
67 | |
68 | |
69 typedef struct { | |
70 ngx_str_t name; | |
71 size_t len; | |
72 ngx_http_log_op_run_pt run; | |
73 } ngx_http_log_var_t; | |
74 | |
75 | |
1071
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
76 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
|
77 u_char *buf, size_t len); |
2072 | 78 static ssize_t ngx_http_log_script_write(ngx_http_request_t *r, |
79 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
|
80 |
290
87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
282
diff
changeset
|
81 static u_char *ngx_http_log_connection(ngx_http_request_t *r, u_char *buf, |
497 | 82 ngx_http_log_op_t *op); |
4539
674227175c4c
- New variable: $connection_requests.
Ruslan Ermilov <ru@nginx.com>
parents:
4499
diff
changeset
|
83 static u_char *ngx_http_log_connection_requests(ngx_http_request_t *r, |
674227175c4c
- New variable: $connection_requests.
Ruslan Ermilov <ru@nginx.com>
parents:
4499
diff
changeset
|
84 u_char *buf, 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
|
85 static u_char *ngx_http_log_pipe(ngx_http_request_t *r, u_char *buf, |
497 | 86 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
|
87 static u_char *ngx_http_log_time(ngx_http_request_t *r, u_char *buf, |
497 | 88 ngx_http_log_op_t *op); |
3873 | 89 static u_char *ngx_http_log_iso8601(ngx_http_request_t *r, u_char *buf, |
90 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
|
91 static u_char *ngx_http_log_msec(ngx_http_request_t *r, u_char *buf, |
497 | 92 ngx_http_log_op_t *op); |
93 static u_char *ngx_http_log_request_time(ngx_http_request_t *r, u_char *buf, | |
94 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
|
95 static u_char *ngx_http_log_status(ngx_http_request_t *r, u_char *buf, |
497 | 96 ngx_http_log_op_t *op); |
573 | 97 static u_char *ngx_http_log_bytes_sent(ngx_http_request_t *r, u_char *buf, |
497 | 98 ngx_http_log_op_t *op); |
577 | 99 static u_char *ngx_http_log_body_bytes_sent(ngx_http_request_t *r, |
573 | 100 u_char *buf, ngx_http_log_op_t *op); |
475 | 101 static u_char *ngx_http_log_request_length(ngx_http_request_t *r, u_char *buf, |
497 | 102 ngx_http_log_op_t *op); |
479 | 103 |
501 | 104 static ngx_int_t ngx_http_log_variable_compile(ngx_conf_t *cf, |
105 ngx_http_log_op_t *op, ngx_str_t *value); | |
106 static size_t ngx_http_log_variable_getlen(ngx_http_request_t *r, | |
107 uintptr_t data); | |
108 static u_char *ngx_http_log_variable(ngx_http_request_t *r, u_char *buf, | |
109 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
|
110 static uintptr_t ngx_http_log_escape(u_char *dst, u_char *src, size_t size); |
501 | 111 |
112 | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
113 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
|
114 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
|
115 static char *ngx_http_log_merge_loc_conf(ngx_conf_t *cf, void *parent, |
497 | 116 void *child); |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
117 static char *ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd, |
497 | 118 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
|
119 static char *ngx_http_log_set_format(ngx_conf_t *cf, ngx_command_t *cmd, |
497 | 120 void *conf); |
573 | 121 static char *ngx_http_log_compile_format(ngx_conf_t *cf, |
2261 | 122 ngx_array_t *flushes, ngx_array_t *ops, ngx_array_t *args, ngx_uint_t s); |
2072 | 123 static char *ngx_http_log_open_file_cache(ngx_conf_t *cf, ngx_command_t *cmd, |
124 void *conf); | |
573 | 125 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
|
126 |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
127 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
128 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
|
129 |
497 | 130 { ngx_string("log_format"), |
131 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_2MORE, | |
132 ngx_http_log_set_format, | |
133 NGX_HTTP_MAIN_CONF_OFFSET, | |
134 0, | |
135 NULL }, | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
136 |
497 | 137 { ngx_string("access_log"), |
645 | 138 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
|
139 |NGX_HTTP_LMT_CONF|NGX_CONF_TAKE123, |
497 | 140 ngx_http_log_set_log, |
141 NGX_HTTP_LOC_CONF_OFFSET, | |
142 0, | |
143 NULL }, | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
144 |
2072 | 145 { ngx_string("open_log_file_cache"), |
146 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1234, | |
147 ngx_http_log_open_file_cache, | |
148 NGX_HTTP_LOC_CONF_OFFSET, | |
149 0, | |
150 NULL }, | |
151 | |
497 | 152 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
|
153 }; |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
154 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
155 |
667 | 156 static ngx_http_module_t ngx_http_log_module_ctx = { |
880 | 157 NULL, /* preconfiguration */ |
573 | 158 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
|
159 |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
160 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
|
161 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
|
162 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
163 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
|
164 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
|
165 |
4499
778ef9c3fd2d
Fixed spelling in single-line comments.
Ruslan Ermilov <ru@nginx.com>
parents:
4494
diff
changeset
|
166 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
|
167 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
|
168 }; |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
169 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
170 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
171 ngx_module_t ngx_http_log_module = { |
509 | 172 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
|
173 &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
|
174 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
|
175 NGX_HTTP_MODULE, /* module type */ |
541 | 176 NULL, /* init master */ |
573 | 177 NULL, /* init module */ |
541 | 178 NULL, /* init process */ |
179 NULL, /* init thread */ | |
180 NULL, /* exit thread */ | |
181 NULL, /* exit process */ | |
182 NULL, /* exit master */ | |
183 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
|
184 }; |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
185 |
26
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
186 |
1074 | 187 static ngx_str_t ngx_http_access_log = ngx_string(NGX_HTTP_LOG_PATH); |
573 | 188 |
189 | |
190 static ngx_str_t ngx_http_combined_fmt = | |
581 | 191 ngx_string("$remote_addr - $remote_user [$time_local] " |
577 | 192 "\"$request\" $status $body_bytes_sent " |
573 | 193 "\"$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
|
194 |
26
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
195 |
573 | 196 static ngx_http_log_var_t ngx_http_log_vars[] = { |
197 { ngx_string("connection"), NGX_ATOMIC_T_LEN, ngx_http_log_connection }, | |
4539
674227175c4c
- New variable: $connection_requests.
Ruslan Ermilov <ru@nginx.com>
parents:
4499
diff
changeset
|
198 { ngx_string("connection_requests"), NGX_INT_T_LEN, |
674227175c4c
- New variable: $connection_requests.
Ruslan Ermilov <ru@nginx.com>
parents:
4499
diff
changeset
|
199 ngx_http_log_connection_requests }, |
573 | 200 { ngx_string("pipe"), 1, ngx_http_log_pipe }, |
581 | 201 { ngx_string("time_local"), sizeof("28/Sep/1970:12:00:00 +0600") - 1, |
573 | 202 ngx_http_log_time }, |
3873 | 203 { ngx_string("time_iso8601"), sizeof("1970-09-28T12:00:00+06:00") - 1, |
204 ngx_http_log_iso8601 }, | |
573 | 205 { 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
|
206 { ngx_string("request_time"), NGX_TIME_T_LEN + 4, |
6e2216ad2c87
$request_time has millisecond precision
Igor Sysoev <igor@sysoev.ru>
parents:
1161
diff
changeset
|
207 ngx_http_log_request_time }, |
4710
5a4666d4b6cb
Merge of r4636, r4637, r4638: config sanity checks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4539
diff
changeset
|
208 { ngx_string("status"), NGX_INT_T_LEN, ngx_http_log_status }, |
573 | 209 { ngx_string("bytes_sent"), NGX_OFF_T_LEN, ngx_http_log_bytes_sent }, |
577 | 210 { ngx_string("body_bytes_sent"), NGX_OFF_T_LEN, |
211 ngx_http_log_body_bytes_sent }, | |
573 | 212 { ngx_string("apache_bytes_sent"), NGX_OFF_T_LEN, |
577 | 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 |
497 | 221 ngx_int_t |
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; |
571 | 228 ngx_open_file_t *file; |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
229 ngx_http_log_op_t *op; |
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 | |
270 file = log[l].file; | |
271 | |
2072 | 272 if (file && file->buffer) { |
571 | 273 |
274 if (len > (size_t) (file->last - file->pos)) { | |
275 | |
1071
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
276 ngx_http_log_write(r, &log[l], file->buffer, |
bd4202f92581
log a failure of the writing to access_log once per minute
Igor Sysoev <igor@sysoev.ru>
parents:
905
diff
changeset
|
277 file->pos - file->buffer); |
571 | 278 |
279 file->pos = file->buffer; | |
280 } | |
281 | |
282 if (len <= (size_t) (file->last - file->pos)) { | |
283 | |
284 p = file->pos; | |
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 | |
292 file->pos = p; | |
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 | |
497 | 477 static u_char * |
478 ngx_http_log_copy_short(ngx_http_request_t *r, u_char *buf, | |
479 ngx_http_log_op_t *op) | |
479 | 480 { |
481 size_t len; | |
482 uintptr_t data; | |
483 | |
484 len = op->len; | |
485 data = op->data; | |
486 | |
487 while (len--) { | |
488 *buf++ = (u_char) (data & 0xff); | |
489 data >>= 8; | |
490 } | |
491 | |
492 return buf; | |
493 } | |
494 | |
495 | |
497 | 496 static u_char * |
497 ngx_http_log_copy_long(ngx_http_request_t *r, u_char *buf, | |
498 ngx_http_log_op_t *op) | |
479 | 499 { |
500 return ngx_cpymem(buf, (u_char *) op->data, op->len); | |
501 } | |
502 | |
503 | |
497 | 504 static u_char * |
505 ngx_http_log_connection(ngx_http_request_t *r, u_char *buf, | |
506 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
|
507 { |
4539
674227175c4c
- New variable: $connection_requests.
Ruslan Ermilov <ru@nginx.com>
parents:
4499
diff
changeset
|
508 return ngx_sprintf(buf, "%uA", r->connection->number); |
674227175c4c
- New variable: $connection_requests.
Ruslan Ermilov <ru@nginx.com>
parents:
4499
diff
changeset
|
509 } |
674227175c4c
- New variable: $connection_requests.
Ruslan Ermilov <ru@nginx.com>
parents:
4499
diff
changeset
|
510 |
674227175c4c
- New variable: $connection_requests.
Ruslan Ermilov <ru@nginx.com>
parents:
4499
diff
changeset
|
511 |
674227175c4c
- New variable: $connection_requests.
Ruslan Ermilov <ru@nginx.com>
parents:
4499
diff
changeset
|
512 static u_char * |
674227175c4c
- New variable: $connection_requests.
Ruslan Ermilov <ru@nginx.com>
parents:
4499
diff
changeset
|
513 ngx_http_log_connection_requests(ngx_http_request_t *r, u_char *buf, |
674227175c4c
- New variable: $connection_requests.
Ruslan Ermilov <ru@nginx.com>
parents:
4499
diff
changeset
|
514 ngx_http_log_op_t *op) |
674227175c4c
- New variable: $connection_requests.
Ruslan Ermilov <ru@nginx.com>
parents:
4499
diff
changeset
|
515 { |
674227175c4c
- New variable: $connection_requests.
Ruslan Ermilov <ru@nginx.com>
parents:
4499
diff
changeset
|
516 return ngx_sprintf(buf, "%ui", r->connection->requests); |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
517 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
518 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
519 |
497 | 520 static u_char * |
521 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
|
522 { |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
523 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
|
524 *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
|
525 } else { |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
526 *buf = '.'; |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
527 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
528 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
529 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
|
530 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
531 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
532 |
497 | 533 static u_char * |
534 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
|
535 { |
178
a8ff48d26cca
nginx-0.0.1-2003-11-11-00:09:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
177
diff
changeset
|
536 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
|
537 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
|
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 |
3873 | 540 static u_char * |
541 ngx_http_log_iso8601(ngx_http_request_t *r, u_char *buf, ngx_http_log_op_t *op) | |
542 { | |
543 return ngx_cpymem(buf, ngx_cached_http_log_iso8601.data, | |
544 ngx_cached_http_log_iso8601.len); | |
545 } | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
546 |
497 | 547 static u_char * |
548 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
|
549 { |
563 | 550 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
|
551 |
563 | 552 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
|
553 |
563 | 554 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
|
555 } |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
393
diff
changeset
|
556 |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
393
diff
changeset
|
557 |
497 | 558 static u_char * |
559 ngx_http_log_request_time(ngx_http_request_t *r, u_char *buf, | |
560 ngx_http_log_op_t *op) | |
561 { | |
1179
6e2216ad2c87
$request_time has millisecond precision
Igor Sysoev <igor@sysoev.ru>
parents:
1161
diff
changeset
|
562 ngx_time_t *tp; |
6e2216ad2c87
$request_time has millisecond precision
Igor Sysoev <igor@sysoev.ru>
parents:
1161
diff
changeset
|
563 ngx_msec_int_t ms; |
6e2216ad2c87
$request_time has millisecond precision
Igor Sysoev <igor@sysoev.ru>
parents:
1161
diff
changeset
|
564 |
6e2216ad2c87
$request_time has millisecond precision
Igor Sysoev <igor@sysoev.ru>
parents:
1161
diff
changeset
|
565 tp = ngx_timeofday(); |
497 | 566 |
1640 | 567 ms = (ngx_msec_int_t) |
568 ((tp->sec - r->start_sec) * 1000 + (tp->msec - r->start_msec)); | |
3515 | 569 ms = ngx_max(ms, 0); |
497 | 570 |
1179
6e2216ad2c87
$request_time has millisecond precision
Igor Sysoev <igor@sysoev.ru>
parents:
1161
diff
changeset
|
571 return ngx_sprintf(buf, "%T.%03M", ms / 1000, ms % 1000); |
497 | 572 } |
573 | |
574 | |
575 static u_char * | |
576 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
|
577 { |
3370
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
578 ngx_uint_t status; |
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
579 |
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
580 if (r->err_status) { |
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
581 status = r->err_status; |
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
582 |
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
583 } 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
|
584 status = r->headers_out.status; |
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
585 |
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
586 } else if (r->http_version == NGX_HTTP_VERSION_9) { |
4726
dad38cdaf496
Merge of r4686, r4687: $status variable.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4710
diff
changeset
|
587 status = 9; |
3370
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
588 |
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
589 } else { |
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
590 status = 0; |
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
591 } |
bfe37ab335b5
log proxied HTTP/0.9 responses status as "009"
Igor Sysoev <igor@sysoev.ru>
parents:
3275
diff
changeset
|
592 |
4710
5a4666d4b6cb
Merge of r4636, r4637, r4638: config sanity checks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4539
diff
changeset
|
593 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
|
594 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
595 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
596 |
497 | 597 static u_char * |
573 | 598 ngx_http_log_bytes_sent(ngx_http_request_t *r, u_char *buf, |
599 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
|
600 { |
455 | 601 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
|
602 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
603 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
604 |
1271 | 605 /* |
606 * although there is a real $body_bytes_sent variable, | |
607 * this log operation code function is more optimized for logging | |
608 */ | |
609 | |
497 | 610 static u_char * |
577 | 611 ngx_http_log_body_bytes_sent(ngx_http_request_t *r, u_char *buf, |
497 | 612 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
|
613 { |
497 | 614 off_t length; |
615 | |
616 length = r->connection->sent - r->header_size; | |
617 | |
618 if (length > 0) { | |
619 return ngx_sprintf(buf, "%O", length); | |
620 } | |
621 | |
622 *buf = '0'; | |
623 | |
624 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
|
625 } |
00cafae0bdf1
nginx-0.0.1-2003-12-14-23:10:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
626 |
00cafae0bdf1
nginx-0.0.1-2003-12-14-23:10:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
627 |
497 | 628 static u_char * |
629 ngx_http_log_request_length(ngx_http_request_t *r, u_char *buf, | |
630 ngx_http_log_op_t *op) | |
475 | 631 { |
663 | 632 return ngx_sprintf(buf, "%O", r->request_length); |
475 | 633 } |
634 | |
635 | |
497 | 636 static ngx_int_t |
501 | 637 ngx_http_log_variable_compile(ngx_conf_t *cf, ngx_http_log_op_t *op, |
638 ngx_str_t *value) | |
639 { | |
509 | 640 ngx_int_t index; |
501 | 641 |
509 | 642 index = ngx_http_get_variable_index(cf, value); |
643 if (index == NGX_ERROR) { | |
501 | 644 return NGX_ERROR; |
645 } | |
646 | |
647 op->len = 0; | |
648 op->getlen = ngx_http_log_variable_getlen; | |
649 op->run = ngx_http_log_variable; | |
509 | 650 op->data = index; |
501 | 651 |
652 return NGX_OK; | |
653 } | |
654 | |
655 | |
656 static size_t | |
657 ngx_http_log_variable_getlen(ngx_http_request_t *r, uintptr_t data) | |
658 { | |
2008
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
659 uintptr_t len; |
501 | 660 ngx_http_variable_value_t *value; |
661 | |
662 value = ngx_http_get_indexed_variable(r, data); | |
663 | |
573 | 664 if (value == NULL || value->not_found) { |
501 | 665 return 1; |
666 } | |
667 | |
2008
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
668 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
|
669 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
670 value->escape = len ? 1 : 0; |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
671 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
672 return value->len + len * 3; |
501 | 673 } |
674 | |
675 | |
676 static u_char * | |
677 ngx_http_log_variable(ngx_http_request_t *r, u_char *buf, ngx_http_log_op_t *op) | |
678 { | |
679 ngx_http_variable_value_t *value; | |
680 | |
681 value = ngx_http_get_indexed_variable(r, op->data); | |
682 | |
573 | 683 if (value == NULL || value->not_found) { |
501 | 684 *buf = '-'; |
685 return buf + 1; | |
686 } | |
687 | |
2008
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
688 if (value->escape == 0) { |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
689 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
|
690 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
691 } else { |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
692 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
|
693 } |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
694 } |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
695 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
696 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
697 static uintptr_t |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
698 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
|
699 { |
3275 | 700 ngx_uint_t n; |
2008
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
701 static u_char hex[] = "0123456789ABCDEF"; |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
702 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
703 static uint32_t escape[] = { |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
704 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
|
705 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
706 /* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */ |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
707 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
|
708 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
709 /* _^]\ [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
|
710 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
|
711 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
712 /* ~}| {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
|
713 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
|
714 |
4191
08d8af70760c
Improved access log escaping to better protect other software.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4133
diff
changeset
|
715 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
|
716 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
|
717 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
|
718 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
|
719 }; |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
720 |
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 if (dst == NULL) { |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
723 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
724 /* 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
|
725 |
3115 | 726 n = 0; |
2008
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
727 |
3275 | 728 while (size) { |
2008
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
729 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
|
730 n++; |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
731 } |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
732 src++; |
3275 | 733 size--; |
2008
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
734 } |
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 return (uintptr_t) n; |
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 |
3275 | 739 while (size) { |
2008
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
740 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
|
741 *dst++ = '\\'; |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
742 *dst++ = 'x'; |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
743 *dst++ = hex[*src >> 4]; |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
744 *dst++ = hex[*src & 0xf]; |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
745 src++; |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
746 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
747 } else { |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
748 *dst++ = *src++; |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
749 } |
3275 | 750 size--; |
2008
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 |
66dc85397a90
escape 0x00-0x1f, ", and \ in access log variables
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
753 return (uintptr_t) dst; |
501 | 754 } |
755 | |
756 | |
497 | 757 static void * |
758 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
|
759 { |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
760 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
|
761 |
573 | 762 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
|
763 |
501 | 764 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_log_main_conf_t)); |
765 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
|
766 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
|
767 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
768 |
497 | 769 if (ngx_array_init(&conf->formats, cf->pool, 4, sizeof(ngx_http_log_fmt_t)) |
573 | 770 != NGX_OK) |
497 | 771 { |
2912
c7d57b539248
return NULL instead of NGX_CONF_ERROR on a create conf failure
Igor Sysoev <igor@sysoev.ru>
parents:
2756
diff
changeset
|
772 return NULL; |
497 | 773 } |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
774 |
573 | 775 fmt = ngx_array_push(&conf->formats); |
776 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
|
777 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
|
778 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
779 |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
780 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
|
781 |
2261 | 782 fmt->flushes = NULL; |
783 | |
573 | 784 fmt->ops = ngx_array_create(cf->pool, 16, sizeof(ngx_http_log_op_t)); |
785 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
|
786 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
|
787 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
788 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
789 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
|
790 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
791 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
792 |
497 | 793 static void * |
794 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
|
795 { |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
796 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
|
797 |
501 | 798 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_log_loc_conf_t)); |
799 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
|
800 return NULL; |
427
0d08eabe5c7b
nginx-0.0.10-2004-09-15-20:00:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
801 } |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
802 |
2072 | 803 conf->open_file_cache = NGX_CONF_UNSET_PTR; |
804 | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
805 return conf; |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
806 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
807 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
808 |
497 | 809 static char * |
810 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
|
811 { |
176
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 *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
|
813 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
|
814 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
815 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
|
816 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
|
817 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
|
818 |
2072 | 819 if (conf->open_file_cache == NGX_CONF_UNSET_PTR) { |
820 | |
821 conf->open_file_cache = prev->open_file_cache; | |
822 conf->open_file_cache_valid = prev->open_file_cache_valid; | |
823 conf->open_file_cache_min_uses = prev->open_file_cache_min_uses; | |
824 | |
825 if (conf->open_file_cache == NGX_CONF_UNSET_PTR) { | |
826 conf->open_file_cache = NULL; | |
827 } | |
828 } | |
829 | |
1074 | 830 if (conf->logs || conf->off) { |
831 return NGX_CONF_OK; | |
832 } | |
427
0d08eabe5c7b
nginx-0.0.10-2004-09-15-20:00:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
833 |
2078
9acbc5e7bcbd
fix variable access_log merging
Igor Sysoev <igor@sysoev.ru>
parents:
2077
diff
changeset
|
834 conf->logs = prev->logs; |
9acbc5e7bcbd
fix variable access_log merging
Igor Sysoev <igor@sysoev.ru>
parents:
2077
diff
changeset
|
835 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
|
836 |
1074 | 837 if (conf->logs || conf->off) { |
838 return NGX_CONF_OK; | |
839 } | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
840 |
1074 | 841 conf->logs = ngx_array_create(cf->pool, 2, sizeof(ngx_http_log_t)); |
842 if (conf->logs == NULL) { | |
843 return NGX_CONF_ERROR; | |
844 } | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
845 |
1074 | 846 log = ngx_array_push(conf->logs); |
847 if (log == NULL) { | |
848 return NGX_CONF_ERROR; | |
849 } | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
850 |
1074 | 851 log->file = ngx_conf_open_file(cf->cycle, &ngx_http_access_log); |
852 if (log->file == NULL) { | |
853 return NGX_CONF_ERROR; | |
854 } | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
855 |
2080
a24c7009de0b
NULL script in default access_log
Igor Sysoev <igor@sysoev.ru>
parents:
2078
diff
changeset
|
856 log->script = NULL; |
1074 | 857 log->disk_full_time = 0; |
858 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
|
859 |
1074 | 860 lmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_log_module); |
861 fmt = lmcf->formats.elts; | |
862 | |
863 /* the default "combined" format */ | |
2261 | 864 log->format = &fmt[0]; |
1074 | 865 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
|
866 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
867 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
|
868 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
869 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
870 |
497 | 871 static char * |
872 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
|
873 { |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
874 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
|
875 |
2072 | 876 ssize_t buf; |
877 ngx_uint_t i, n; | |
878 ngx_str_t *value, name; | |
879 ngx_http_log_t *log; | |
880 ngx_http_log_fmt_t *fmt; | |
881 ngx_http_log_main_conf_t *lmcf; | |
882 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
|
883 |
427
0d08eabe5c7b
nginx-0.0.10-2004-09-15-20:00:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
884 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
|
885 |
0d08eabe5c7b
nginx-0.0.10-2004-09-15-20:00:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
886 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
|
887 llcf->off = 1; |
3038
cd8738e76610
strict testing "access_log off"
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
888 if (cf->args->nelts == 2) { |
cd8738e76610
strict testing "access_log off"
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
889 return NGX_CONF_OK; |
cd8738e76610
strict testing "access_log off"
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
890 } |
cd8738e76610
strict testing "access_log off"
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
891 |
cd8738e76610
strict testing "access_log off"
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
892 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
cd8738e76610
strict testing "access_log off"
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
893 "invalid parameter \"%V\"", &value[2]); |
cd8738e76610
strict testing "access_log off"
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
894 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
|
895 } |
0d08eabe5c7b
nginx-0.0.10-2004-09-15-20:00:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
896 |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
897 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
|
898 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
|
899 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
|
900 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
|
901 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
902 } |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
69
diff
changeset
|
903 |
393
5659d773cfa8
nginx-0.0.7-2004-07-15-20:35:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
356
diff
changeset
|
904 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
|
905 |
501 | 906 log = ngx_array_push(llcf->logs); |
907 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
|
908 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
|
909 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
910 |
2072 | 911 ngx_memzero(log, sizeof(ngx_http_log_t)); |
912 | |
913 n = ngx_http_script_variables_count(&value[1]); | |
914 | |
915 if (n == 0) { | |
916 log->file = ngx_conf_open_file(cf->cycle, &value[1]); | |
917 if (log->file == NULL) { | |
918 return NGX_CONF_ERROR; | |
919 } | |
920 | |
921 } else { | |
2536
a6d6d762c554
small optimization: " == NGX_ERROR" > " != NGX_OK"
Igor Sysoev <igor@sysoev.ru>
parents:
2277
diff
changeset
|
922 if (ngx_conf_full_name(cf->cycle, &value[1], 0) != NGX_OK) { |
2072 | 923 return NGX_CONF_ERROR; |
924 } | |
925 | |
926 log->script = ngx_pcalloc(cf->pool, sizeof(ngx_http_log_script_t)); | |
927 if (log->script == NULL) { | |
928 return NGX_CONF_ERROR; | |
929 } | |
930 | |
931 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t)); | |
932 | |
933 sc.cf = cf; | |
934 sc.source = &value[1]; | |
935 sc.lengths = &log->script->lengths; | |
936 sc.values = &log->script->values; | |
937 sc.variables = n; | |
938 sc.complete_lengths = 1; | |
939 sc.complete_values = 1; | |
940 | |
941 if (ngx_http_script_compile(&sc) != NGX_OK) { | |
942 return NGX_CONF_ERROR; | |
943 } | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
944 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
945 |
571 | 946 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
|
947 name = value[2]; |
581 | 948 |
949 if (ngx_strcmp(name.data, "combined") == 0) { | |
950 lmcf->combined_used = 1; | |
951 } | |
952 | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
953 } else { |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3515
diff
changeset
|
954 ngx_str_set(&name, "combined"); |
573 | 955 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
|
956 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
957 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
958 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
|
959 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
|
960 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
|
961 && 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
|
962 { |
2261 | 963 log->format = &fmt[i]; |
571 | 964 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
|
965 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
966 } |
100
7ebc8b7fb816
nginx-0.0.1-2003-06-03-19:42:58 import
Igor Sysoev <igor@sysoev.ru>
parents:
99
diff
changeset
|
967 |
487 | 968 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
969 "unknown log format \"%V\"", &name); | |
571 | 970 return NGX_CONF_ERROR; |
487 | 971 |
571 | 972 buffer: |
973 | |
974 if (cf->args->nelts == 4) { | |
975 if (ngx_strncmp(value[3].data, "buffer=", 7) != 0) { | |
976 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
977 "invalid parameter \"%V\"", &value[3]); | |
978 return NGX_CONF_ERROR; | |
979 } | |
980 | |
2072 | 981 if (log->script) { |
982 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
|
983 "buffered logs cannot have variables in name"); |
2072 | 984 return NGX_CONF_ERROR; |
985 } | |
986 | |
571 | 987 name.len = value[3].len - 7; |
988 name.data = value[3].data + 7; | |
989 | |
990 buf = ngx_parse_size(&name); | |
991 | |
992 if (buf == NGX_ERROR) { | |
993 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
|
994 "invalid buffer value \"%V\"", &name); |
571 | 995 return NGX_CONF_ERROR; |
996 } | |
997 | |
998 if (log->file->buffer && log->file->last - log->file->pos != buf) { | |
999 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1000 "access_log \"%V\" already defined " | |
1001 "with different buffer size", &value[1]); | |
1002 return NGX_CONF_ERROR; | |
1003 } | |
1004 | |
1005 log->file->buffer = ngx_palloc(cf->pool, buf); | |
1006 if (log->file->buffer == NULL) { | |
1007 return NGX_CONF_ERROR; | |
1008 } | |
1009 | |
1010 log->file->pos = log->file->buffer; | |
1011 log->file->last = log->file->buffer + buf; | |
1012 } | |
1013 | |
1014 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
|
1015 } |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1016 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1017 |
497 | 1018 static char * |
1019 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
|
1020 { |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1021 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
|
1022 |
573 | 1023 ngx_str_t *value; |
1024 ngx_uint_t i; | |
1025 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
|
1026 |
4327
73d37e1ccb91
- Improved error message when parsing of the "buffer" parameter of the
Ruslan Ermilov <ru@nginx.com>
parents:
4191
diff
changeset
|
1027 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
|
1028 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
|
1029 "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
|
1030 "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
|
1031 } |
73d37e1ccb91
- Improved error message when parsing of the "buffer" parameter of the
Ruslan Ermilov <ru@nginx.com>
parents:
4191
diff
changeset
|
1032 |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1033 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
|
1034 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1035 fmt = lmcf->formats.elts; |
573 | 1036 for (i = 0; i < lmcf->formats.nelts; i++) { |
1037 if (fmt[i].name.len == value[1].len | |
1038 && 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
|
1039 { |
2036 | 1040 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
1041 "duplicate \"log_format\" name \"%V\"", | |
1042 &value[1]); | |
1043 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
|
1044 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1045 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1046 |
501 | 1047 fmt = ngx_array_push(&lmcf->formats); |
1048 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
|
1049 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
|
1050 } |
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 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
|
1053 |
2261 | 1054 fmt->flushes = ngx_array_create(cf->pool, 4, sizeof(ngx_int_t)); |
1055 if (fmt->flushes == NULL) { | |
1056 return NGX_CONF_ERROR; | |
1057 } | |
1058 | |
573 | 1059 fmt->ops = ngx_array_create(cf->pool, 16, sizeof(ngx_http_log_op_t)); |
501 | 1060 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
|
1061 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
|
1062 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1063 |
2261 | 1064 return ngx_http_log_compile_format(cf, fmt->flushes, fmt->ops, cf->args, 2); |
573 | 1065 } |
1066 | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1067 |
573 | 1068 static char * |
2261 | 1069 ngx_http_log_compile_format(ngx_conf_t *cf, ngx_array_t *flushes, |
1070 ngx_array_t *ops, ngx_array_t *args, ngx_uint_t s) | |
573 | 1071 { |
880 | 1072 u_char *data, *p, ch; |
1073 size_t i, len; | |
1074 ngx_str_t *value, var; | |
2261 | 1075 ngx_int_t *flush; |
880 | 1076 ngx_uint_t bracket; |
1077 ngx_http_log_op_t *op; | |
1078 ngx_http_log_var_t *v; | |
573 | 1079 |
1080 value = args->elts; | |
1081 | |
1082 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
|
1083 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1084 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
|
1085 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1086 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
|
1087 |
573 | 1088 op = ngx_array_push(ops); |
501 | 1089 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
|
1090 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
|
1091 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1092 |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1093 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
|
1094 |
880 | 1095 if (value[s].data[i] == '$') { |
569 | 1096 |
1097 if (++i == value[s].len) { | |
1098 goto invalid; | |
1099 } | |
1100 | |
1101 if (value[s].data[i] == '{') { | |
1102 bracket = 1; | |
1103 | |
1104 if (++i == value[s].len) { | |
1105 goto invalid; | |
1106 } | |
1107 | |
1108 var.data = &value[s].data[i]; | |
1109 | |
1110 } else { | |
1111 bracket = 0; | |
1112 var.data = &value[s].data[i]; | |
1113 } | |
1114 | |
1115 for (var.len = 0; i < value[s].len; i++, var.len++) { | |
1116 ch = value[s].data[i]; | |
1117 | |
1118 if (ch == '}' && bracket) { | |
1119 i++; | |
1120 bracket = 0; | |
1121 break; | |
1122 } | |
1123 | |
1124 if ((ch >= 'A' && ch <= 'Z') | |
1125 || (ch >= 'a' && ch <= 'z') | |
1126 || (ch >= '0' && ch <= '9') | |
1127 || ch == '_') | |
1128 { | |
1129 continue; | |
1130 } | |
1131 | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1132 break; |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1133 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1134 |
569 | 1135 if (bracket) { |
1136 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1137 "the closing bracket in \"%V\" " | |
1138 "variable is missing", &var); | |
1139 return NGX_CONF_ERROR; | |
1140 } | |
1141 | |
1142 if (var.len == 0) { | |
1143 goto invalid; | |
1144 } | |
1145 | |
577 | 1146 if (ngx_strncmp(var.data, "apache_bytes_sent", 17) == 0) { |
1147 ngx_conf_log_error(NGX_LOG_WARN, cf, 0, | |
1148 "use \"$body_bytes_sent\" instead of " | |
1149 "\"$apache_bytes_sent\""); | |
1150 } | |
1151 | |
573 | 1152 for (v = ngx_http_log_vars; v->name.len; v++) { |
1153 | |
1154 if (v->name.len == var.len | |
1155 && ngx_strncmp(v->name.data, var.data, var.len) == 0) | |
1156 { | |
1157 op->len = v->len; | |
1158 op->getlen = NULL; | |
1159 op->run = v->run; | |
1160 op->data = 0; | |
1161 | |
1162 goto found; | |
1163 } | |
1164 } | |
1165 | |
569 | 1166 if (ngx_http_log_variable_compile(cf, op, &var) != NGX_OK) { |
1167 return NGX_CONF_ERROR; | |
1168 } | |
1169 | |
2261 | 1170 if (flushes) { |
1171 | |
1172 flush = ngx_array_push(flushes); | |
1173 if (flush == NULL) { | |
1174 return NGX_CONF_ERROR; | |
1175 } | |
1176 | |
1177 *flush = op->data; /* variable index */ | |
1178 } | |
1179 | |
573 | 1180 found: |
1181 | |
1182 continue; | |
1183 } | |
1184 | |
1185 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
|
1186 |
880 | 1187 while (i < value[s].len && value[s].data[i] != '$') { |
573 | 1188 i++; |
1189 } | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1190 |
573 | 1191 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
|
1192 |
573 | 1193 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
|
1194 |
573 | 1195 op->len = len; |
1196 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
|
1197 |
573 | 1198 if (len <= sizeof(uintptr_t)) { |
1199 op->run = ngx_http_log_copy_short; | |
1200 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
|
1201 |
573 | 1202 while (len--) { |
1203 op->data <<= 8; | |
1204 op->data |= data[len]; | |
1205 } | |
1206 | |
1207 } else { | |
1208 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
|
1209 |
2049 | 1210 p = ngx_pnalloc(cf->pool, len); |
573 | 1211 if (p == NULL) { |
1212 return NGX_CONF_ERROR; | |
1213 } | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1214 |
573 | 1215 ngx_memcpy(p, data, len); |
1216 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
|
1217 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1218 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1219 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1220 } |
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1221 |
569 | 1222 return NGX_CONF_OK; |
1223 | |
1224 invalid: | |
1225 | |
1226 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "invalid parameter \"%s\"", data); | |
1227 | |
1228 return NGX_CONF_ERROR; | |
1229 } | |
1230 | |
176
c0552e5ab567
nginx-0.0.1-2003-11-09-23:03:38 import; separate building
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
1231 |
2072 | 1232 static char * |
1233 ngx_http_log_open_file_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
1234 { | |
1235 ngx_http_log_loc_conf_t *llcf = conf; | |
1236 | |
1237 time_t inactive, valid; | |
1238 ngx_str_t *value, s; | |
1239 ngx_int_t max, min_uses; | |
1240 ngx_uint_t i; | |
1241 | |
1242 if (llcf->open_file_cache != NGX_CONF_UNSET_PTR) { | |
1243 return "is duplicate"; | |
1244 } | |
1245 | |
1246 value = cf->args->elts; | |
1247 | |
1248 max = 0; | |
1249 inactive = 10; | |
1250 valid = 60; | |
1251 min_uses = 1; | |
1252 | |
1253 for (i = 1; i < cf->args->nelts; i++) { | |
1254 | |
1255 if (ngx_strncmp(value[i].data, "max=", 4) == 0) { | |
1256 | |
1257 max = ngx_atoi(value[i].data + 4, value[i].len - 4); | |
1258 if (max == NGX_ERROR) { | |
1259 goto failed; | |
1260 } | |
1261 | |
1262 continue; | |
1263 } | |
1264 | |
1265 if (ngx_strncmp(value[i].data, "inactive=", 9) == 0) { | |
1266 | |
1267 s.len = value[i].len - 9; | |
1268 s.data = value[i].data + 9; | |
1269 | |
1270 inactive = ngx_parse_time(&s, 1); | |
4474 | 1271 if (inactive == (time_t) NGX_ERROR) { |
2072 | 1272 goto failed; |
1273 } | |
1274 | |
1275 continue; | |
1276 } | |
1277 | |
1278 if (ngx_strncmp(value[i].data, "min_uses=", 9) == 0) { | |
1279 | |
1280 min_uses = ngx_atoi(value[i].data + 9, value[i].len - 9); | |
1281 if (min_uses == NGX_ERROR) { | |
1282 goto failed; | |
1283 } | |
1284 | |
1285 continue; | |
1286 } | |
1287 | |
1288 if (ngx_strncmp(value[i].data, "valid=", 6) == 0) { | |
1289 | |
1290 s.len = value[i].len - 6; | |
1291 s.data = value[i].data + 6; | |
1292 | |
1293 valid = ngx_parse_time(&s, 1); | |
4474 | 1294 if (valid == (time_t) NGX_ERROR) { |
2072 | 1295 goto failed; |
1296 } | |
1297 | |
1298 continue; | |
1299 } | |
1300 | |
1301 if (ngx_strcmp(value[i].data, "off") == 0) { | |
1302 | |
1303 llcf->open_file_cache = NULL; | |
1304 | |
1305 continue; | |
1306 } | |
1307 | |
1308 failed: | |
1309 | |
1310 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1311 "invalid \"open_log_file_cache\" parameter \"%V\"", | |
1312 &value[i]); | |
1313 return NGX_CONF_ERROR; | |
1314 } | |
1315 | |
1316 if (llcf->open_file_cache == NULL) { | |
1317 return NGX_CONF_OK; | |
1318 } | |
1319 | |
1320 if (max == 0) { | |
1321 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1322 "\"open_log_file_cache\" must have \"max\" parameter"); | |
1323 return NGX_CONF_ERROR; | |
1324 } | |
1325 | |
1326 llcf->open_file_cache = ngx_open_file_cache_init(cf->pool, max, inactive); | |
1327 | |
1328 if (llcf->open_file_cache) { | |
1329 | |
1330 llcf->open_file_cache_valid = valid; | |
1331 llcf->open_file_cache_min_uses = min_uses; | |
1332 | |
1333 return NGX_CONF_OK; | |
1334 } | |
1335 | |
1336 return NGX_CONF_ERROR; | |
1337 } | |
1338 | |
1339 | |
569 | 1340 static ngx_int_t |
573 | 1341 ngx_http_log_init(ngx_conf_t *cf) |
569 | 1342 { |
573 | 1343 ngx_str_t *value; |
1344 ngx_array_t a; | |
581 | 1345 ngx_http_handler_pt *h; |
573 | 1346 ngx_http_log_fmt_t *fmt; |
1347 ngx_http_log_main_conf_t *lmcf; | |
569 | 1348 ngx_http_core_main_conf_t *cmcf; |
1349 | |
573 | 1350 lmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_log_module); |
1351 | |
1352 if (lmcf->combined_used) { | |
1353 if (ngx_array_init(&a, cf->pool, 1, sizeof(ngx_str_t)) != NGX_OK) { | |
1354 return NGX_ERROR; | |
1355 } | |
1356 | |
1357 value = ngx_array_push(&a); | |
1358 if (value == NULL) { | |
1359 return NGX_ERROR; | |
1360 } | |
1361 | |
1362 *value = ngx_http_combined_fmt; | |
1363 fmt = lmcf->formats.elts; | |
1364 | |
2261 | 1365 if (ngx_http_log_compile_format(cf, NULL, fmt->ops, &a, 0) |
573 | 1366 != NGX_CONF_OK) |
1367 { | |
1368 return NGX_ERROR; | |
1369 } | |
1370 } | |
1371 | |
1372 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module); | |
569 | 1373 |
581 | 1374 h = ngx_array_push(&cmcf->phases[NGX_HTTP_LOG_PHASE].handlers); |
1375 if (h == NULL) { | |
1376 return NGX_ERROR; | |
1377 } | |
1378 | |
1379 *h = ngx_http_log_handler; | |
569 | 1380 |
1381 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
|
1382 } |