src/server/safs/addlog.c

changeset 657
f1469e3144a7
parent 415
d938228c382e
equal deleted inserted replaced
656:59dd1fb27639 657:f1469e3144a7
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29 #include <stdio.h> 29 #include <stdio.h>
30 #include <stdlib.h> 30 #include <stdlib.h>
31 #include <inttypes.h>
31 32
32 #include "addlog.h" 33 #include "addlog.h"
33 34
34 #include "../daemon/request.h" 35 #include "../daemon/request.h"
35 #include "../daemon/vserver.h" 36 #include "../daemon/vserver.h"
36 #include "../daemon/log.h" 37 #include "../daemon/log.h"
37 #include "../util/util.h" 38 #include "../util/util.h"
39 #include "../util/io.h"
38 40
39 int common_log(pblock *pb, Session *sn, Request *rq) { 41 int common_log(pblock *pb, Session *sn, Request *rq) {
40 NSAPIRequest *request = (NSAPIRequest*)rq; 42 NSAPIRequest *request = (NSAPIRequest*)rq;
41 VirtualServer *vs = request->vs; 43 VirtualServer *vs = request->vs;
42 AccessLog *log = vs->log; 44 AccessLog *log = vs->log;
57 char *time = ctime(&t); 59 char *time = ctime(&t);
58 char *req = pblock_findval("clf-request", rq->reqpb); 60 char *req = pblock_findval("clf-request", rq->reqpb);
59 61
60 // hack to get the content length 62 // hack to get the content length
61 // http_start_response should not modify the header names 63 // http_start_response should not modify the header names
62 char *len = pblock_findval("Content-length", rq->srvhdrs); 64 int64_t len = httpstream_written(sn->csd);
63 65
64 if(!ip) { 66 if(!ip) {
65 ip = "-"; 67 ip = "-";
66 } 68 }
67 if(!user) { 69 if(!user) {
68 user = "-"; 70 user = "-";
69 }
70 if(!len) {
71 len = "0";
72 } 71 }
73 72
74 // remove trailing line feed 73 // remove trailing line feed
75 cxstring tmstr = cx_str(time); 74 cxstring tmstr = cx_str(time);
76 if(tmstr.ptr[tmstr.length-1] == '\n') { 75 if(tmstr.ptr[tmstr.length-1] == '\n') {
90 user_agent = "-"; 89 user_agent = "-";
91 uaq = 0; 90 uaq = 0;
92 } 91 }
93 fprintf( 92 fprintf(
94 log->log->file, 93 log->log->file,
95 "%s - %s [%.*s] \"%s\" %d %s %.*s%s%.*s %.*s%s%.*s\n", 94 "%s - %s [%.*s] \"%s\" %d %" PRId64 " %.*s%s%.*s %.*s%s%.*s\n",
96 ip, 95 ip,
97 user, 96 user,
98 (int)tmstr.length, 97 (int)tmstr.length,
99 tmstr.ptr, 98 tmstr.ptr,
100 req, 99 req,
101 rq->status_num, 100 (int)rq->status_num,
102 len, 101 len,
103 refq, 102 refq,
104 "\"", 103 "\"",
105 referer, 104 referer,
106 refq, 105 refq,
112 "\"" 111 "\""
113 ); 112 );
114 } else { 113 } else {
115 fprintf( 114 fprintf(
116 log->log->file, 115 log->log->file,
117 "%s - %s [%.*s] \"%s\" %d %s\n", 116 "%s - %s [%.*s] \"%s\" %d %" PRId64 "\n",
118 ip, 117 ip,
119 user, 118 user,
120 (int)tmstr.length, 119 (int)tmstr.length,
121 tmstr.ptr, 120 tmstr.ptr,
122 req, 121 req,

mercurial