Re: "Runtime" logging into access.log. How?

From: Michal Matusiak <m.matusiak@dont-contact.us>
Date: Wed, 02 Jun 2004 23:11:23 +0200

Slivarez! wrote:
> Hi all.
>
> I need to make squid-2.5.STABLE5 write information into access.log during downloading process but not after downloading whole file. Is there any official patches for that?
>
> P.S. I have found patch-aa for squid-2.5.STABLE1, but it does not work (even in STABLE1). Maybe somebody can find an errors in this patch?

i've written the patch for squid-2.5.stable5
you can patch and test ;)

two things:
1. after ./configure ...
(but before make!!!)
you have to write this line in file include/autoconf.h:
#define ACCLOG

2. make sure you have option "emulate_httpd_log" off in your squid.conf

after this you should see in access.log two lines
.... GET http://url DOWNLOAD START ...
.... GET http://url DOWNLOAD END ...

any suggestions welcome

michal matusiak

diff -urNbB squid-2.5.STABLE5/src/access_log.c squid-2.5.STABLE5-acclog/src/access_log.c
--- squid-2.5.STABLE5/src/access_log.c 2003-07-28 10:59:28.000000000 +0200
+++ squid-2.5.STABLE5-acclog/src/access_log.c 2004-06-02 22:45:58.000000000 +0200
@@ -245,6 +245,26 @@
         client = inet_ntoa(al->cache.caddr);
     user = accessLogFormatName(al->cache.authuser ?
         al->cache.authuser : al->cache.rfc931);
+#ifdef ACCLOG
+if (al->info) {
+ logfilePrintf(logfile, "%9d.%03d %6d %s %s/%03d %ld %s %s %s %s %s%s/%s %s",
+ (int) current_time.tv_sec,
+ (int) current_time.tv_usec / 1000,
+ al->cache.msec,
+ client,
+ log_tags[al->cache.code],
+ al->http.code,
+ (long int) al->cache.size,
+ al->private.method_str,
+ al->url,
+ al->info,
+ user && *user ? user : dash_str,
+ al->hier.ping.timedout ? "TIMEOUT_" : "",
+ hier_strings[al->hier.code],
+ al->hier.host,
+ al->http.content_type);
+} else {
+#endif
     logfilePrintf(logfile, "%9d.%03d %6d %s %s/%03d %ld %s %s %s %s%s/%s %s",
         (int) current_time.tv_sec,
         (int) current_time.tv_usec / 1000,
@@ -260,6 +280,9 @@
         hier_strings[al->hier.code],
         al->hier.host,
         al->http.content_type);
+#ifdef ACCLOG
+}
+#endif
     safe_free(user);
 }
 
diff -urNbB squid-2.5.STABLE5/src/client_side.c squid-2.5.STABLE5-acclog/src/client_side.c
--- squid-2.5.STABLE5/src/client_side.c 2004-02-18 19:51:16.000000000 +0100
+++ squid-2.5.STABLE5-acclog/src/client_side.c 2004-06-02 22:45:58.000000000 +0200
@@ -859,6 +859,9 @@
             packerClean(&p);
             memBufClean(&mb);
         }
+#ifdef ACCLOG
+http->al.info = "DOWNLOAD END";
+#endif
         accessLogLog(&http->al);
         clientUpdateCounters(http);
         clientdbUpdate(conn->peer.sin_addr, http->log_type, PROTO_HTTP, http->out.size);
@@ -2178,6 +2181,13 @@
 {
     clientHttpRequest *http = data;
     StoreEntry *entry = http->entry;
+
+#ifdef ACCLOG
+ MemObject *mem = NULL;
+ ConnStateData *conn = http->conn;
+ request_t *request = http->request;
+#endif
+
     int done;
     http->out.size += size;
     debug(33, 5) ("clientWriteComplete: FD %d, sz %ld, err %d, off %ld, len %d\n",
@@ -2187,6 +2197,52 @@
         if (isTcpHit(http->log_type))
             kb_incr(&statCounter.client_http.hit_kbytes_out, size);
     }
+
+#ifdef ACCLOG
+ debug(33,1) ("clientWriteComplete: before accessLog handling code\n");
+ if (!http->flags.acclog_done)
+ {
+ http->flags.acclog_done = 1;
+ if (http->entry)
+ mem = http->entry->mem_obj;
+ if (http->out.size || http->log_type) {
+ http->al.icp.opcode = ICP_INVALID;
+ http->al.url = http->log_uri;
+ if (mem) {
+ http->al.http.code = mem->reply->sline.status;
+ http->al.http.content_type = strBuf(mem->reply->content_type);
+ }
+ http->al.cache.caddr = conn->log_addr;
+ http->al.cache.size = http->out.size;
+ http->al.cache.code = http->log_type;
+ http->al.cache.msec = tvSubMsec(http->start, current_time);
+ if (request) {
+ Packer p;
+ MemBuf mb;
+ memBufDefInit(&mb);
+ packerToMemInit(&p, &mb);
+ httpHeaderPackInto(&request->header, &p);
+ http->al.http.method = request->method;
+ http->al.http.version = request->http_ver;
+ http->al.headers.request = xstrdup(mb.buf);
+ http->al.hier = request->hier;
+ if (request->auth_user_request) {
+ if (authenticateUserRequestUsername(request->auth_user_request))
+ http->al.cache.authuser = xstrdup(authenticateUserRequestUsername(request->auth_user_request));
+ authenticateAuthUserRequestUnlock(request->auth_user_request);
+ request->auth_user_request = NULL;
+ }
+ if (conn->rfc931[0])
+ http->al.cache.rfc931 = conn->rfc931;
+ packerClean(&p);
+ memBufClean(&mb);
+ }
+ http->al.info = "DOWNLOAD START";
+ accessLogLog(&http->al);
+ }
+}
+#endif
+
 #if SIZEOF_SIZE_T == 4
     if (http->out.size > 0x7FFF0000) {
         debug(33, 1) ("WARNING: closing FD %d to prevent counter overflow\n", fd);
diff -urNbB squid-2.5.STABLE5/src/structs.h squid-2.5.STABLE5-acclog/src/structs.h
--- squid-2.5.STABLE5/src/structs.h 2004-02-04 18:42:28.000000000 +0100
+++ squid-2.5.STABLE5-acclog/src/structs.h 2004-06-02 22:45:58.000000000 +0200
@@ -1051,6 +1051,9 @@
         const char *method_str;
     } private;
     HierarchyLogEntry hier;
+#ifdef ACCLOG
+ char *info;
+#endif
 };
 
 struct _clientHttpRequest {
@@ -1083,6 +1086,9 @@
         unsigned int internal:1;
         unsigned int done_copying:1;
         unsigned int purging:1;
+#ifdef ACCLOG
+ unsigned int acclog_done:1;
+#endif
     } flags;
     struct {
         http_status status;
Received on Wed Jun 02 2004 - 19:54:16 MDT

This archive was generated by hypermail pre-2.1.9 : Wed Jun 30 2004 - 12:00:03 MDT