comparison src/http/modules/ngx_http_log_module.c @ 412:b246022ef454 NGINX_0_7_18

nginx 0.7.18 *) Change: the "underscores_in_headers" directive; now nginx does not allows underscores in a client request header line names. *) Feature: the ngx_http_secure_link_module. *) Feature: the "real_ip_header" directive supports any header. *) Feature: the "log_subrequest" directive. *) Feature: the $realpath_root variable. *) Feature: the "http_502" and "http_504" parameters of the "proxy_next_upstream" directive. *) Bugfix: the "http_503" parameter of the "proxy_next_upstream" or "fastcgi_next_upstream" directives did not work. *) Bugfix: nginx might send a "Transfer-Encoding: chunked" heaer line for HEAD requests. *) Bugfix: now accept threshold depends on worker_connections.
author Igor Sysoev <http://sysoev.ru>
date Mon, 13 Oct 2008 00:00:00 +0400
parents a8e3f1441eec
children b4f69f2ef02c
comparison
equal deleted inserted replaced
411:b453a4324c60 412:b246022ef454
26 }; 26 };
27 27
28 28
29 typedef struct { 29 typedef struct {
30 ngx_str_t name; 30 ngx_str_t name;
31 ngx_array_t *flushes;
31 ngx_array_t *ops; /* array of ngx_http_log_op_t */ 32 ngx_array_t *ops; /* array of ngx_http_log_op_t */
32 } ngx_http_log_fmt_t; 33 } ngx_http_log_fmt_t;
33 34
34 35
35 typedef struct { 36 typedef struct {
47 typedef struct { 48 typedef struct {
48 ngx_open_file_t *file; 49 ngx_open_file_t *file;
49 ngx_http_log_script_t *script; 50 ngx_http_log_script_t *script;
50 time_t disk_full_time; 51 time_t disk_full_time;
51 time_t error_log_time; 52 time_t error_log_time;
52 ngx_array_t *ops; /* array of ngx_http_log_op_t */ 53 ngx_http_log_fmt_t *format;
53 } ngx_http_log_t; 54 } ngx_http_log_t;
54 55
55 56
56 typedef struct { 57 typedef struct {
57 ngx_array_t *logs; /* array of ngx_http_log_t */ 58 ngx_array_t *logs; /* array of ngx_http_log_t */
111 static char *ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd, 112 static char *ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd,
112 void *conf); 113 void *conf);
113 static char *ngx_http_log_set_format(ngx_conf_t *cf, ngx_command_t *cmd, 114 static char *ngx_http_log_set_format(ngx_conf_t *cf, ngx_command_t *cmd,
114 void *conf); 115 void *conf);
115 static char *ngx_http_log_compile_format(ngx_conf_t *cf, 116 static char *ngx_http_log_compile_format(ngx_conf_t *cf,
116 ngx_array_t *ops, ngx_array_t *args, ngx_uint_t s); 117 ngx_array_t *flushes, ngx_array_t *ops, ngx_array_t *args, ngx_uint_t s);
117 static char *ngx_http_log_open_file_cache(ngx_conf_t *cf, ngx_command_t *cmd, 118 static char *ngx_http_log_open_file_cache(ngx_conf_t *cf, ngx_command_t *cmd,
118 void *conf); 119 void *conf);
119 static ngx_int_t ngx_http_log_init(ngx_conf_t *cf); 120 static ngx_int_t ngx_http_log_init(ngx_conf_t *cf);
120 121
121 122
240 */ 241 */
241 242
242 continue; 243 continue;
243 } 244 }
244 245
246 ngx_http_script_flush_no_cacheable_variables(r, log[l].format->flushes);
247
245 len = 0; 248 len = 0;
246 op = log[l].ops->elts; 249 op = log[l].format->ops->elts;
247 for (i = 0; i < log[l].ops->nelts; i++) { 250 for (i = 0; i < log[l].format->ops->nelts; i++) {
248 if (op[i].len == 0) { 251 if (op[i].len == 0) {
249 len += op[i].getlen(r, op[i].data); 252 len += op[i].getlen(r, op[i].data);
250 253
251 } else { 254 } else {
252 len += op[i].len; 255 len += op[i].len;
269 272
270 if (len <= (size_t) (file->last - file->pos)) { 273 if (len <= (size_t) (file->last - file->pos)) {
271 274
272 p = file->pos; 275 p = file->pos;
273 276
274 for (i = 0; i < log[l].ops->nelts; i++) { 277 for (i = 0; i < log[l].format->ops->nelts; i++) {
275 p = op[i].run(r, p, &op[i]); 278 p = op[i].run(r, p, &op[i]);
276 } 279 }
277 280
278 ngx_linefeed(p); 281 ngx_linefeed(p);
279 282
288 return NGX_ERROR; 291 return NGX_ERROR;
289 } 292 }
290 293
291 p = line; 294 p = line;
292 295
293 for (i = 0; i < log[l].ops->nelts; i++) { 296 for (i = 0; i < log[l].format->ops->nelts; i++) {
294 p = op[i].run(r, p, &op[i]); 297 p = op[i].run(r, p, &op[i]);
295 } 298 }
296 299
297 ngx_linefeed(p); 300 ngx_linefeed(p);
298 301
724 } 727 }
725 728
726 fmt->name.len = sizeof("combined") - 1; 729 fmt->name.len = sizeof("combined") - 1;
727 fmt->name.data = (u_char *) "combined"; 730 fmt->name.data = (u_char *) "combined";
728 731
732 fmt->flushes = NULL;
733
729 fmt->ops = ngx_array_create(cf->pool, 16, sizeof(ngx_http_log_op_t)); 734 fmt->ops = ngx_array_create(cf->pool, 16, sizeof(ngx_http_log_op_t));
730 if (fmt->ops == NULL) { 735 if (fmt->ops == NULL) {
731 return NGX_CONF_ERROR; 736 return NGX_CONF_ERROR;
732 } 737 }
733 738
804 809
805 lmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_log_module); 810 lmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_log_module);
806 fmt = lmcf->formats.elts; 811 fmt = lmcf->formats.elts;
807 812
808 /* the default "combined" format */ 813 /* the default "combined" format */
809 log->ops = fmt[0].ops; 814 log->format = &fmt[0];
810 lmcf->combined_used = 1; 815 lmcf->combined_used = 1;
811 816
812 return NGX_CONF_OK; 817 return NGX_CONF_OK;
813 } 818 }
814 819
898 fmt = lmcf->formats.elts; 903 fmt = lmcf->formats.elts;
899 for (i = 0; i < lmcf->formats.nelts; i++) { 904 for (i = 0; i < lmcf->formats.nelts; i++) {
900 if (fmt[i].name.len == name.len 905 if (fmt[i].name.len == name.len
901 && ngx_strcasecmp(fmt[i].name.data, name.data) == 0) 906 && ngx_strcasecmp(fmt[i].name.data, name.data) == 0)
902 { 907 {
903 log->ops = fmt[i].ops; 908 log->format = &fmt[i];
904 goto buffer; 909 goto buffer;
905 } 910 }
906 } 911 }
907 912
908 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, 913 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
983 return NGX_CONF_ERROR; 988 return NGX_CONF_ERROR;
984 } 989 }
985 990
986 fmt->name = value[1]; 991 fmt->name = value[1];
987 992
993 fmt->flushes = ngx_array_create(cf->pool, 4, sizeof(ngx_int_t));
994 if (fmt->flushes == NULL) {
995 return NGX_CONF_ERROR;
996 }
997
988 fmt->ops = ngx_array_create(cf->pool, 16, sizeof(ngx_http_log_op_t)); 998 fmt->ops = ngx_array_create(cf->pool, 16, sizeof(ngx_http_log_op_t));
989 if (fmt->ops == NULL) { 999 if (fmt->ops == NULL) {
990 return NGX_CONF_ERROR; 1000 return NGX_CONF_ERROR;
991 } 1001 }
992 1002
993 return ngx_http_log_compile_format(cf, fmt->ops, cf->args, 2); 1003 return ngx_http_log_compile_format(cf, fmt->flushes, fmt->ops, cf->args, 2);
994 } 1004 }
995 1005
996 1006
997 static char * 1007 static char *
998 ngx_http_log_compile_format(ngx_conf_t *cf, ngx_array_t *ops, 1008 ngx_http_log_compile_format(ngx_conf_t *cf, ngx_array_t *flushes,
999 ngx_array_t *args, ngx_uint_t s) 1009 ngx_array_t *ops, ngx_array_t *args, ngx_uint_t s)
1000 { 1010 {
1001 u_char *data, *p, ch; 1011 u_char *data, *p, ch;
1002 size_t i, len; 1012 size_t i, len;
1003 ngx_str_t *value, var; 1013 ngx_str_t *value, var;
1014 ngx_int_t *flush;
1004 ngx_uint_t bracket; 1015 ngx_uint_t bracket;
1005 ngx_http_log_op_t *op; 1016 ngx_http_log_op_t *op;
1006 ngx_http_log_var_t *v; 1017 ngx_http_log_var_t *v;
1007 1018
1008 value = args->elts; 1019 value = args->elts;
1112 1123
1113 if (ngx_http_log_variable_compile(cf, op, &var) != NGX_OK) { 1124 if (ngx_http_log_variable_compile(cf, op, &var) != NGX_OK) {
1114 return NGX_CONF_ERROR; 1125 return NGX_CONF_ERROR;
1115 } 1126 }
1116 1127
1128 if (flushes) {
1129
1130 flush = ngx_array_push(flushes);
1131 if (flush == NULL) {
1132 return NGX_CONF_ERROR;
1133 }
1134
1135 *flush = op->data; /* variable index */
1136 }
1137
1117 found: 1138 found:
1118 1139
1119 continue; 1140 continue;
1120 } 1141 }
1121 1142
1297 } 1318 }
1298 1319
1299 *value = ngx_http_combined_fmt; 1320 *value = ngx_http_combined_fmt;
1300 fmt = lmcf->formats.elts; 1321 fmt = lmcf->formats.elts;
1301 1322
1302 if (ngx_http_log_compile_format(cf, fmt->ops, &a, 0) 1323 if (ngx_http_log_compile_format(cf, NULL, fmt->ops, &a, 0)
1303 != NGX_CONF_OK) 1324 != NGX_CONF_OK)
1304 { 1325 {
1305 return NGX_ERROR; 1326 return NGX_ERROR;
1306 } 1327 }
1307 } 1328 }