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