comparison src/http/ngx_http_upstream.c @ 880:3b763d36e055

axe old % log format
author Igor Sysoev <igor@sysoev.ru>
date Mon, 27 Nov 2006 14:46:15 +0000
parents a164e55b4067
children 4d68c486fcb0
comparison
equal deleted inserted replaced
879:804514cb0758 880:3b763d36e055
68 #if (NGX_HTTP_GZIP) 68 #if (NGX_HTTP_GZIP)
69 static ngx_int_t ngx_http_upstream_copy_content_encoding(ngx_http_request_t *r, 69 static ngx_int_t ngx_http_upstream_copy_content_encoding(ngx_http_request_t *r,
70 ngx_table_elt_t *h, ngx_uint_t offset); 70 ngx_table_elt_t *h, ngx_uint_t offset);
71 #endif 71 #endif
72 72
73 static size_t ngx_http_upstream_log_status_getlen(ngx_http_request_t *r,
74 uintptr_t data);
75 static u_char *ngx_http_upstream_log_status(ngx_http_request_t *r,
76 u_char *buf, ngx_http_log_op_t *op);
77 static size_t ngx_http_upstream_log_response_time_getlen(ngx_http_request_t *r,
78 uintptr_t data);
79 static u_char *ngx_http_upstream_log_response_time(ngx_http_request_t *r,
80 u_char *buf, ngx_http_log_op_t *op);
81
82 static ngx_int_t ngx_http_upstream_add_variables(ngx_conf_t *cf); 73 static ngx_int_t ngx_http_upstream_add_variables(ngx_conf_t *cf);
83 static ngx_int_t ngx_http_upstream_status_variable(ngx_http_request_t *r, 74 static ngx_int_t ngx_http_upstream_status_variable(ngx_http_request_t *r,
84 ngx_http_variable_value_t *v, uintptr_t data); 75 ngx_http_variable_value_t *v, uintptr_t data);
85 static ngx_int_t ngx_http_upstream_response_time_variable(ngx_http_request_t *r, 76 static ngx_int_t ngx_http_upstream_response_time_variable(ngx_http_request_t *r,
86 ngx_http_variable_value_t *v, uintptr_t data); 77 ngx_http_variable_value_t *v, uintptr_t data);
263 NULL, /* exit master */ 254 NULL, /* exit master */
264 NGX_MODULE_V1_PADDING 255 NGX_MODULE_V1_PADDING
265 }; 256 };
266 257
267 258
268 static ngx_http_log_op_name_t ngx_http_upstream_log_fmt_ops[] = {
269 { ngx_string("upstream_status"), 0, NULL,
270 ngx_http_upstream_log_status_getlen,
271 ngx_http_upstream_log_status },
272 { ngx_string("upstream_response_time"), 0, NULL,
273 ngx_http_upstream_log_response_time_getlen,
274 ngx_http_upstream_log_response_time },
275 { ngx_null_string, 0, NULL, NULL, NULL }
276 };
277
278
279 static ngx_http_variable_t ngx_http_upstream_vars[] = { 259 static ngx_http_variable_t ngx_http_upstream_vars[] = {
280 260
281 { ngx_string("upstream_status"), NULL, 261 { ngx_string("upstream_status"), NULL,
282 ngx_http_upstream_status_variable, 0, NGX_HTTP_VAR_NOHASH, 0 }, 262 ngx_http_upstream_status_variable, 0, NGX_HTTP_VAR_NOHASH, 0 },
283 263
2479 } 2459 }
2480 2460
2481 #endif 2461 #endif
2482 2462
2483 2463
2484 static size_t
2485 ngx_http_upstream_log_status_getlen(ngx_http_request_t *r, uintptr_t data)
2486 {
2487 if (r->upstream) {
2488 return r->upstream->states.nelts * (3 + 2);
2489 }
2490
2491 return 1;
2492 }
2493
2494
2495 static u_char *
2496 ngx_http_upstream_log_status(ngx_http_request_t *r, u_char *buf,
2497 ngx_http_log_op_t *op)
2498 {
2499 ngx_uint_t i;
2500 ngx_http_upstream_t *u;
2501 ngx_http_upstream_state_t *state;
2502
2503 u = r->upstream;
2504
2505 if (u == NULL || u->states.nelts == 0) {
2506 *buf = '-';
2507 return buf + 1;
2508 }
2509
2510 i = 0;
2511 state = u->states.elts;
2512
2513 for ( ;; ) {
2514 if (state[i].status == 0) {
2515 *buf++ = '-';
2516
2517 } else {
2518 buf = ngx_sprintf(buf, "%ui", state[i].status);
2519 }
2520
2521 if (++i == u->states.nelts) {
2522 return buf;
2523 }
2524
2525 *buf++ = ',';
2526 *buf++ = ' ';
2527 }
2528 }
2529
2530
2531 static size_t
2532 ngx_http_upstream_log_response_time_getlen(ngx_http_request_t *r,
2533 uintptr_t data)
2534 {
2535 if (r->upstream) {
2536 return r->upstream->states.nelts * (NGX_TIME_T_LEN + 4 + 2);
2537 }
2538
2539 return 1;
2540 }
2541
2542
2543 static u_char *
2544 ngx_http_upstream_log_response_time(ngx_http_request_t *r, u_char *buf,
2545 ngx_http_log_op_t *op)
2546 {
2547 ngx_uint_t i;
2548 ngx_http_upstream_t *u;
2549 ngx_http_upstream_state_t *state;
2550
2551 u = r->upstream;
2552
2553 if (u == NULL || u->states.nelts == 0) {
2554 *buf = '-';
2555 return buf + 1;
2556 }
2557
2558 i = 0;
2559 state = u->states.elts;
2560
2561 for ( ;; ) {
2562 if (state[i].status == 0) {
2563 *buf++ = '-';
2564
2565 } else {
2566 buf = ngx_sprintf(buf, "%d.%03d",
2567 state[i].response_time / 1000,
2568 state[i].response_time % 1000);
2569 }
2570
2571 if (++i == u->states.nelts) {
2572 return buf;
2573 }
2574
2575 *buf++ = ',';
2576 *buf++ = ' ';
2577 }
2578 }
2579
2580
2581 static ngx_int_t 2464 static ngx_int_t
2582 ngx_http_upstream_add_variables(ngx_conf_t *cf) 2465 ngx_http_upstream_add_variables(ngx_conf_t *cf)
2583 { 2466 {
2584 ngx_http_variable_t *var, *v; 2467 ngx_http_variable_t *var, *v;
2585 ngx_http_log_op_name_t *op;
2586 2468
2587 for (v = ngx_http_upstream_vars; v->name.len; v++) { 2469 for (v = ngx_http_upstream_vars; v->name.len; v++) {
2588 var = ngx_http_add_variable(cf, &v->name, v->flags); 2470 var = ngx_http_add_variable(cf, &v->name, v->flags);
2589 if (var == NULL) { 2471 if (var == NULL) {
2590 return NGX_ERROR; 2472 return NGX_ERROR;
2591 } 2473 }
2592 2474
2593 var->get_handler = v->get_handler; 2475 var->get_handler = v->get_handler;
2594 var->data = v->data; 2476 var->data = v->data;
2595 } 2477 }
2596
2597 for (op = ngx_http_upstream_log_fmt_ops; op->name.len; op++) { /* void */ }
2598 op->run = NULL;
2599
2600 for (op = ngx_http_log_fmt_ops; op->run; op++) {
2601 if (op->name.len == 0) {
2602 op = (ngx_http_log_op_name_t *) op->run;
2603 }
2604 }
2605
2606 op->run = (ngx_http_log_op_run_pt) ngx_http_upstream_log_fmt_ops;
2607 2478
2608 return NGX_OK; 2479 return NGX_OK;
2609 } 2480 }
2610 2481
2611 2482