From: hno <> Date: Thu, 3 Mar 2005 03:57:34 +0000 (+0000) Subject: Add support for seding access.log via syslog X-Git-Tag: SQUID_3_0_PRE4~865 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c33aa074d7abab587f479c0954e6526a1316ed4a;p=thirdparty%2Fsquid.git Add support for seding access.log via syslog --- diff --git a/src/cf.data.pre b/src/cf.data.pre index adb65c1e43..60022f7852 100644 --- a/src/cf.data.pre +++ b/src/cf.data.pre @@ -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 diff --git a/src/logfile.cc b/src/logfile.cc index 05adda25bb..52db87283a 100644 --- a/src/logfile.cc +++ b/src/logfile.cc @@ -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(xcalloc(1, sizeof(*lf))); - lf = static_cast(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); diff --git a/src/structs.h b/src/structs.h index b48af134b1..8d5399a58a 100644 --- a/src/structs.h +++ b/src/structs.h @@ -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