Mercurial > hg > nginx-mail
comparison src/http/modules/ngx_http_log_module.c @ 665:0b460e61bdcd default tip
Merge with nginx 1.0.0.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 25 Apr 2011 04:22:17 +0400 |
parents | 8214eaef3530 |
children |
comparison
equal
deleted
inserted
replaced
572:06419a2298a9 | 665:0b460e61bdcd |
---|---|
80 static u_char *ngx_http_log_connection(ngx_http_request_t *r, u_char *buf, | 80 static u_char *ngx_http_log_connection(ngx_http_request_t *r, u_char *buf, |
81 ngx_http_log_op_t *op); | 81 ngx_http_log_op_t *op); |
82 static u_char *ngx_http_log_pipe(ngx_http_request_t *r, u_char *buf, | 82 static u_char *ngx_http_log_pipe(ngx_http_request_t *r, u_char *buf, |
83 ngx_http_log_op_t *op); | 83 ngx_http_log_op_t *op); |
84 static u_char *ngx_http_log_time(ngx_http_request_t *r, u_char *buf, | 84 static u_char *ngx_http_log_time(ngx_http_request_t *r, u_char *buf, |
85 ngx_http_log_op_t *op); | |
86 static u_char *ngx_http_log_iso8601(ngx_http_request_t *r, u_char *buf, | |
85 ngx_http_log_op_t *op); | 87 ngx_http_log_op_t *op); |
86 static u_char *ngx_http_log_msec(ngx_http_request_t *r, u_char *buf, | 88 static u_char *ngx_http_log_msec(ngx_http_request_t *r, u_char *buf, |
87 ngx_http_log_op_t *op); | 89 ngx_http_log_op_t *op); |
88 static u_char *ngx_http_log_request_time(ngx_http_request_t *r, u_char *buf, | 90 static u_char *ngx_http_log_request_time(ngx_http_request_t *r, u_char *buf, |
89 ngx_http_log_op_t *op); | 91 ngx_http_log_op_t *op); |
191 static ngx_http_log_var_t ngx_http_log_vars[] = { | 193 static ngx_http_log_var_t ngx_http_log_vars[] = { |
192 { ngx_string("connection"), NGX_ATOMIC_T_LEN, ngx_http_log_connection }, | 194 { ngx_string("connection"), NGX_ATOMIC_T_LEN, ngx_http_log_connection }, |
193 { ngx_string("pipe"), 1, ngx_http_log_pipe }, | 195 { ngx_string("pipe"), 1, ngx_http_log_pipe }, |
194 { ngx_string("time_local"), sizeof("28/Sep/1970:12:00:00 +0600") - 1, | 196 { ngx_string("time_local"), sizeof("28/Sep/1970:12:00:00 +0600") - 1, |
195 ngx_http_log_time }, | 197 ngx_http_log_time }, |
198 { ngx_string("time_iso8601"), sizeof("1970-09-28T12:00:00+06:00") - 1, | |
199 ngx_http_log_iso8601 }, | |
196 { ngx_string("msec"), NGX_TIME_T_LEN + 4, ngx_http_log_msec }, | 200 { ngx_string("msec"), NGX_TIME_T_LEN + 4, ngx_http_log_msec }, |
197 { ngx_string("request_time"), NGX_TIME_T_LEN + 4, | 201 { ngx_string("request_time"), NGX_TIME_T_LEN + 4, |
198 ngx_http_log_request_time }, | 202 ngx_http_log_request_time }, |
199 { ngx_string("status"), 3, ngx_http_log_status }, | 203 { ngx_string("status"), 3, ngx_http_log_status }, |
200 { ngx_string("bytes_sent"), NGX_OFF_T_LEN, ngx_http_log_bytes_sent }, | 204 { ngx_string("bytes_sent"), NGX_OFF_T_LEN, ngx_http_log_bytes_sent }, |
508 { | 512 { |
509 return ngx_cpymem(buf, ngx_cached_http_log_time.data, | 513 return ngx_cpymem(buf, ngx_cached_http_log_time.data, |
510 ngx_cached_http_log_time.len); | 514 ngx_cached_http_log_time.len); |
511 } | 515 } |
512 | 516 |
517 static u_char * | |
518 ngx_http_log_iso8601(ngx_http_request_t *r, u_char *buf, ngx_http_log_op_t *op) | |
519 { | |
520 return ngx_cpymem(buf, ngx_cached_http_log_iso8601.data, | |
521 ngx_cached_http_log_iso8601.len); | |
522 } | |
513 | 523 |
514 static u_char * | 524 static u_char * |
515 ngx_http_log_msec(ngx_http_request_t *r, u_char *buf, ngx_http_log_op_t *op) | 525 ngx_http_log_msec(ngx_http_request_t *r, u_char *buf, ngx_http_log_op_t *op) |
516 { | 526 { |
517 ngx_time_t *tp; | 527 ngx_time_t *tp; |
531 | 541 |
532 tp = ngx_timeofday(); | 542 tp = ngx_timeofday(); |
533 | 543 |
534 ms = (ngx_msec_int_t) | 544 ms = (ngx_msec_int_t) |
535 ((tp->sec - r->start_sec) * 1000 + (tp->msec - r->start_msec)); | 545 ((tp->sec - r->start_sec) * 1000 + (tp->msec - r->start_msec)); |
536 ms = (ms >= 0) ? ms : 0; | 546 ms = ngx_max(ms, 0); |
537 | 547 |
538 return ngx_sprintf(buf, "%T.%03M", ms / 1000, ms % 1000); | 548 return ngx_sprintf(buf, "%T.%03M", ms / 1000, ms % 1000); |
539 } | 549 } |
540 | 550 |
541 | 551 |
542 static u_char * | 552 static u_char * |
543 ngx_http_log_status(ngx_http_request_t *r, u_char *buf, ngx_http_log_op_t *op) | 553 ngx_http_log_status(ngx_http_request_t *r, u_char *buf, ngx_http_log_op_t *op) |
544 { | 554 { |
545 return ngx_sprintf(buf, "%ui", | 555 ngx_uint_t status; |
546 r->err_status ? r->err_status : r->headers_out.status); | 556 |
557 if (r->err_status) { | |
558 status = r->err_status; | |
559 | |
560 } else if (r->headers_out.status) { | |
561 status = r->headers_out.status; | |
562 | |
563 } else if (r->http_version == NGX_HTTP_VERSION_9) { | |
564 *buf++ = '0'; | |
565 *buf++ = '0'; | |
566 *buf++ = '9'; | |
567 return buf; | |
568 | |
569 } else { | |
570 status = 0; | |
571 } | |
572 | |
573 return ngx_sprintf(buf, "%ui", status); | |
547 } | 574 } |
548 | 575 |
549 | 576 |
550 static u_char * | 577 static u_char * |
551 ngx_http_log_bytes_sent(ngx_http_request_t *r, u_char *buf, | 578 ngx_http_log_bytes_sent(ngx_http_request_t *r, u_char *buf, |
648 | 675 |
649 | 676 |
650 static uintptr_t | 677 static uintptr_t |
651 ngx_http_log_escape(u_char *dst, u_char *src, size_t size) | 678 ngx_http_log_escape(u_char *dst, u_char *src, size_t size) |
652 { | 679 { |
653 ngx_uint_t i, n; | 680 ngx_uint_t n; |
654 static u_char hex[] = "0123456789ABCDEF"; | 681 static u_char hex[] = "0123456789ABCDEF"; |
655 | 682 |
656 static uint32_t escape[] = { | 683 static uint32_t escape[] = { |
657 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ | 684 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ |
658 | 685 |
676 | 703 |
677 /* find the number of the characters to be escaped */ | 704 /* find the number of the characters to be escaped */ |
678 | 705 |
679 n = 0; | 706 n = 0; |
680 | 707 |
681 for (i = 0; i < size; i++) { | 708 while (size) { |
682 if (escape[*src >> 5] & (1 << (*src & 0x1f))) { | 709 if (escape[*src >> 5] & (1 << (*src & 0x1f))) { |
683 n++; | 710 n++; |
684 } | 711 } |
685 src++; | 712 src++; |
713 size--; | |
686 } | 714 } |
687 | 715 |
688 return (uintptr_t) n; | 716 return (uintptr_t) n; |
689 } | 717 } |
690 | 718 |
691 for (i = 0; i < size; i++) { | 719 while (size) { |
692 if (escape[*src >> 5] & (1 << (*src & 0x1f))) { | 720 if (escape[*src >> 5] & (1 << (*src & 0x1f))) { |
693 *dst++ = '\\'; | 721 *dst++ = '\\'; |
694 *dst++ = 'x'; | 722 *dst++ = 'x'; |
695 *dst++ = hex[*src >> 4]; | 723 *dst++ = hex[*src >> 4]; |
696 *dst++ = hex[*src & 0xf]; | 724 *dst++ = hex[*src & 0xf]; |
697 src++; | 725 src++; |
698 | 726 |
699 } else { | 727 } else { |
700 *dst++ = *src++; | 728 *dst++ = *src++; |
701 } | 729 } |
730 size--; | |
702 } | 731 } |
703 | 732 |
704 return (uintptr_t) dst; | 733 return (uintptr_t) dst; |
705 } | 734 } |
706 | 735 |
726 fmt = ngx_array_push(&conf->formats); | 755 fmt = ngx_array_push(&conf->formats); |
727 if (fmt == NULL) { | 756 if (fmt == NULL) { |
728 return NULL; | 757 return NULL; |
729 } | 758 } |
730 | 759 |
731 fmt->name.len = sizeof("combined") - 1; | 760 ngx_str_set(&fmt->name, "combined"); |
732 fmt->name.data = (u_char *) "combined"; | |
733 | 761 |
734 fmt->flushes = NULL; | 762 fmt->flushes = NULL; |
735 | 763 |
736 fmt->ops = ngx_array_create(cf->pool, 16, sizeof(ngx_http_log_op_t)); | 764 fmt->ops = ngx_array_create(cf->pool, 16, sizeof(ngx_http_log_op_t)); |
737 if (fmt->ops == NULL) { | 765 if (fmt->ops == NULL) { |
901 if (ngx_strcmp(name.data, "combined") == 0) { | 929 if (ngx_strcmp(name.data, "combined") == 0) { |
902 lmcf->combined_used = 1; | 930 lmcf->combined_used = 1; |
903 } | 931 } |
904 | 932 |
905 } else { | 933 } else { |
906 name.len = sizeof("combined") - 1; | 934 ngx_str_set(&name, "combined"); |
907 name.data = (u_char *) "combined"; | |
908 lmcf->combined_used = 1; | 935 lmcf->combined_used = 1; |
909 } | 936 } |
910 | 937 |
911 fmt = lmcf->formats.elts; | 938 fmt = lmcf->formats.elts; |
912 for (i = 0; i < lmcf->formats.nelts; i++) { | 939 for (i = 0; i < lmcf->formats.nelts; i++) { |