adds combined log format

Sun, 21 Jan 2018 09:17:52 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 21 Jan 2018 09:17:52 +0100
changeset 196
0459c94a60ed
parent 195
d367b687bc74
child 197
23fa058ae54b

adds combined log format

src/server/safs/addlog.c file | annotate | diff | comparison | revisions
--- a/src/server/safs/addlog.c	Sun Jan 21 08:54:28 2018 +0100
+++ b/src/server/safs/addlog.c	Sun Jan 21 09:17:52 2018 +0100
@@ -34,12 +34,19 @@
 #include "../daemon/request.h"
 #include "../daemon/vserver.h"
 #include "../daemon/log.h"
+#include "../util/util.h"
 
 int common_log(pblock *pb, Session *sn, Request *rq) {
     NSAPIRequest *request = (NSAPIRequest*)rq;
     VirtualServer *vs = request->vs;
     AccessLog *log = vs->log;
     
+    char *combined_str = pblock_findval("combined", pb);
+    WSBool combined = FALSE;
+    if(combined_str) {
+        combined = util_getboolean(combined_str, FALSE);
+    }
+    
     if(log == NULL) {
         return REQ_NOACTION;
     }
@@ -71,15 +78,50 @@
     }
     tmstr = sstrdup_pool(sn->pool, tmstr);
     
-    fprintf(
-            log->log->file,
-            "%s - %s [%s] \"%s\" %d %s\n",
-            ip,
-            user,
-            tmstr.ptr,
-            req,
-            rq->status_num,
-            len);
+    if(combined) {
+        char *referer = pblock_findval("referer", rq->headers);
+        char *user_agent = pblock_findval("user-agent", rq->headers);
+        int refq = 1;
+        int uaq = 1;
+        if(!referer) {
+            referer = "-";
+            refq = 0;
+        }
+        if(!user_agent) {
+            user_agent = "-";
+            uaq = 0;
+        }
+        fprintf(
+                log->log->file,
+                "%s - %s [%s] \"%s\" %d %s %.*s%s%.*s %.*s%s%.*s\n",
+                ip,
+                user,
+                tmstr.ptr,
+                req,
+                rq->status_num,
+                len,
+                refq,
+                "\"",
+                referer,
+                refq,
+                "\"",
+                uaq,
+                "\"",
+                user_agent,
+                uaq,
+                "\""
+                );
+    } else {
+        fprintf(
+                log->log->file,
+                "%s - %s [%s] \"%s\" %d %s\n",
+                ip,
+                user,
+                tmstr.ptr,
+                req,
+                rq->status_num,
+                len);
+    }
     fflush(log->log->file);
     
     

mercurial