]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Add support for seding access.log via syslog
authorhno <>
Thu, 3 Mar 2005 03:57:34 +0000 (03:57 +0000)
committerhno <>
Thu, 3 Mar 2005 03:57:34 +0000 (03:57 +0000)
src/cf.data.pre
src/logfile.cc
src/structs.h

index adb65c1e4320e4c9a9638093799192b320d80006..60022f785265b7d23373ece4475a2aa2be69a8ab 100644 (file)
@@ -1,6 +1,6 @@
 
 #
-# $Id: cf.data.pre,v 1.376 2005/02/27 16:36:06 serassio Exp $
+# $Id: cf.data.pre,v 1.377 2005/03/02 20:57:34 hno Exp $
 #
 #
 # SQUID Web Proxy Cache          http://www.squid-cache.org/
@@ -1240,7 +1240,10 @@ DOC_START
        ALL the acl's specified (which must be defined in acl clauses).
        If no acl is specified, all requests will be logged to this file.
 
-       To disable logging of a request specify "none".
+       To disable logging of a request use the filepath "none", in which case
+       a logformat name should not be specified.
+
+       To log the request via syslog specify a filepath of "syslog"
 DOC_END
 
 
index 05adda25bb1c5eb74df3eac8eb17cce018dfa537..52db87283a50cda9693d39f1e89163f5a8ed80d7 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: logfile.cc,v 1.15 2003/02/21 22:50:09 robertc Exp $
+ * $Id: logfile.cc,v 1.16 2005/03/02 20:57:35 hno Exp $
  *
  * DEBUG: section 50    Log file handling
  * AUTHOR: Duane Wessels
@@ -42,38 +42,44 @@ Logfile *
 logfileOpen(const char *path, size_t bufsz, int fatal_flag)
 {
     int fd;
-    Logfile *lf;
-    fd = file_open(path, O_WRONLY | O_CREAT | O_TEXT);
-
-    if (DISK_ERROR == fd) {
-        if (ENOENT == errno && fatal_flag) {
-            fatalf("Cannot open '%s' because\n"
-                   "\tthe parent directory does not exist.\n"
-                   "\tPlease create the directory.\n", path);
-        } else if (EACCES == errno && fatal_flag) {
-            fatalf("Cannot open '%s' for writing.\n"
-                   "\tThe parent directory must be writeable by the\n"
-                   "\tuser '%s', which is the cache_effective_user\n"
-                   "\tset in squid.conf.", path, Config.effectiveUser);
-        } else {
-            debug(50, 1) ("logfileOpen: %s: %s\n", path, xstrerror());
-            return NULL;
-        }
-    }
+    Logfile *lf = static_cast<Logfile *>(xcalloc(1, sizeof(*lf)));
 
-    lf = static_cast<Logfile *>(xcalloc(1, sizeof(*lf)));
-    lf->fd = fd;
+    xstrncpy(lf->path, path, MAXPATHLEN);
 
-    if (fatal_flag)
-        lf->flags.fatal = 1;
+    if (strcmp(path, "syslog") == 0) {
+        lf->flags.syslog = 1;
+        lf->syslog_priority = LOG_INFO;
+        lf->fd = -1;
+    } else {
+        fd = file_open(path, O_WRONLY | O_CREAT | O_TEXT);
+
+        if (DISK_ERROR == fd) {
+            if (ENOENT == errno && fatal_flag) {
+                fatalf("Cannot open '%s' because\n"
+                       "\tthe parent directory does not exist.\n"
+                       "\tPlease create the directory.\n", path);
+            } else if (EACCES == errno && fatal_flag) {
+                fatalf("Cannot open '%s' for writing.\n"
+                       "\tThe parent directory must be writeable by the\n"
+                       "\tuser '%s', which is the cache_effective_user\n"
+                       "\tset in squid.conf.", path, Config.effectiveUser);
+            } else {
+                debug(50, 1) ("logfileOpen: %s: %s\n", path, xstrerror());
+                return NULL;
+            }
+        }
 
-    xstrncpy(lf->path, path, MAXPATHLEN);
+        lf->fd = fd;
 
-    if (bufsz > 0) {
-        lf->buf = (char *) xmalloc(bufsz);
-        lf->bufsz = bufsz;
+        if (bufsz > 0) {
+            lf->buf = (char *) xmalloc(bufsz);
+            lf->bufsz = bufsz;
+        }
     }
 
+    if (fatal_flag)
+        lf->flags.fatal = 1;
+
     return lf;
 }
 
@@ -81,7 +87,9 @@ void
 logfileClose(Logfile * lf)
 {
     logfileFlush(lf);
-    file_close(lf->fd);
+
+    if (lf->fd >= 0)
+        file_close(lf->fd);
 
     if (lf->buf)
         xfree(lf->buf);
@@ -101,6 +109,10 @@ logfileRotate(Logfile * lf)
     char from[MAXPATHLEN];
     char to[MAXPATHLEN];
     assert(lf->path);
+
+    if (lf->flags.syslog)
+        return;
+
 #ifdef S_ISREG
 
     if (stat(lf->path, &sb) == 0)
@@ -141,6 +153,11 @@ logfileRotate(Logfile * lf)
 void
 logfileWrite(Logfile * lf, void *buf, size_t len)
 {
+    if (lf->flags.syslog) {
+        syslog(lf->syslog_priority, "%s", (char *)buf);
+        return;
+    }
+
     if (0 == lf->bufsz) {
         /* buffering disabled */
         logfileWriteWrapper(lf, buf, len);
index b48af134b1e6fd295bbdf9753deaba2e45fc8968..8d5399a58a68cfa80a4db1deccbd10a3381f9ac0 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: structs.h,v 1.509 2005/02/27 16:36:07 serassio Exp $
+ * $Id: structs.h,v 1.510 2005/03/02 20:57:35 hno Exp $
  *
  *
  * SQUID Web Proxy Cache          http://www.squid-cache.org/
@@ -2111,12 +2111,13 @@ struct _Logfile
 
     struct
     {
-
-unsigned int fatal:
-        1;
+        unsigned int fatal;
+        unsigned int syslog;
     }
 
     flags;
+
+    int syslog_priority;
 };
 
 struct _logformat