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