--------------------- PatchSet 6453 Date: 2005/03/02 20:50:02 Author: hno Branch: customlog-2_5 Tag: (none) Log: Support logging via syslog Members: src/cf.data.pre:1.49.2.40.2.11->1.49.2.40.2.12 src/logfile.c:1.5.38.3->1.5.38.3.4.1 src/structs.h:1.48.2.11.2.8->1.48.2.11.2.9 Index: squid/src/cf.data.pre =================================================================== RCS file: /cvsroot/squid-sf//squid/src/cf.data.pre,v retrieving revision 1.49.2.40.2.11 retrieving revision 1.49.2.40.2.12 diff -u -r1.49.2.40.2.11 -r1.49.2.40.2.12 --- squid/src/cf.data.pre 29 Sep 2004 21:33:11 -0000 1.49.2.40.2.11 +++ squid/src/cf.data.pre 2 Mar 2005 20:50:02 -0000 1.49.2.40.2.12 @@ -1,6 +1,6 @@ # -# $Id: cf.data.pre,v 1.49.2.40.2.11 2004/09/29 21:33:11 hno Exp $ +# $Id: cf.data.pre,v 1.49.2.40.2.12 2005/03/02 20:50:02 hno Exp $ # # # SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -917,6 +917,8 @@ 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" NOCOMMENT_START access_log @DEFAULT_ACCESS_LOG@ squid NOCOMMENT_END Index: squid/src/logfile.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/logfile.c,v retrieving revision 1.5.38.3 retrieving revision 1.5.38.3.4.1 diff -u -r1.5.38.3 -r1.5.38.3.4.1 --- squid/src/logfile.c 21 Jan 2003 03:15:11 -0000 1.5.38.3 +++ squid/src/logfile.c 2 Mar 2005 20:50:03 -0000 1.5.38.3.4.1 @@ -39,33 +39,38 @@ 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 = xcalloc(1, sizeof(*lf)); + xstrncpy(lf->path, path, MAXPATHLEN); + if (strcmp(path, "syslog") == 0) { + lf->flags.syslog = 1; + lf->syslog_priority = LOG_INFO; + lf->fd = -1; + } else { + int 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()); + safe_free(lf); + return NULL; + } + } + lf->fd = fd; + if (bufsz > 0) { + lf->buf = xmalloc(bufsz); + lf->bufsz = bufsz; } } - lf = xcalloc(1, sizeof(*lf)); - lf->fd = fd; if (fatal_flag) lf->flags.fatal = 1; - xstrncpy(lf->path, path, MAXPATHLEN); - if (bufsz > 0) { - lf->buf = xmalloc(bufsz); - lf->bufsz = bufsz; - } return lf; } @@ -73,7 +78,8 @@ logfileClose(Logfile * lf) { logfileFlush(lf); - file_close(lf->fd); + if (lf->fd >= 0) + file_close(lf->fd); if (lf->buf) xfree(lf->buf); xfree(lf); @@ -89,6 +95,8 @@ char from[MAXPATHLEN]; char to[MAXPATHLEN]; assert(lf->path); + if (lf->flags.syslog) + return; #ifdef S_ISREG if (stat(lf->path, &sb) == 0) if (S_ISREG(sb.st_mode) == 0) @@ -120,6 +128,10 @@ 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: squid/src/structs.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/structs.h,v retrieving revision 1.48.2.11.2.8 retrieving revision 1.48.2.11.2.9 diff -u -r1.48.2.11.2.8 -r1.48.2.11.2.9 --- squid/src/structs.h 29 Sep 2004 21:33:11 -0000 1.48.2.11.2.8 +++ squid/src/structs.h 2 Mar 2005 20:50:03 -0000 1.48.2.11.2.9 @@ -1,6 +1,6 @@ /* - * $Id: structs.h,v 1.48.2.11.2.8 2004/09/29 21:33:11 hno Exp $ + * $Id: structs.h,v 1.48.2.11.2.9 2005/03/02 20:50:03 hno Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -2183,8 +2183,10 @@ size_t bufsz; off_t offset; struct { - unsigned int fatal:1; + unsigned int fatal; + unsigned int syslog; } flags; + int syslog_priority; }; struct _logformat {