#
-# $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/
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
/*
- * $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
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;
}
logfileClose(Logfile * lf)
{
logfileFlush(lf);
- file_close(lf->fd);
+
+ if (lf->fd >= 0)
+ file_close(lf->fd);
if (lf->buf)
xfree(lf->buf);
char from[MAXPATHLEN];
char to[MAXPATHLEN];
assert(lf->path);
+
+ if (lf->flags.syslog)
+ return;
+
#ifdef S_ISREG
if (stat(lf->path, &sb) == 0)
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);