2 * DEBUG: section 50 Log file handling
3 * AUTHOR: Duane Wessels
5 * SQUID Web Proxy Cache http://www.squid-cache.org/
6 * ----------------------------------------------------------
8 * Squid is the result of efforts by numerous individuals from
9 * the Internet community; see the CONTRIBUTORS file for full
10 * details. Many organizations have provided support for Squid's
11 * development; see the SPONSORS file for full details. Squid is
12 * Copyrighted (C) 2001 by the Regents of the University of
13 * California; see the COPYRIGHT file for full details. Squid
14 * incorporates software developed and/or copyrighted by other
15 * sources; see the CREDITS file for full details.
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
33 #include "squid-old.h"
38 #include "log/ModSyslog.h"
40 /* Define LOG_AUTHPRIV as LOG_AUTH on systems still using the old deprecated LOG_AUTH */
41 #if !defined(LOG_AUTHPRIV) && defined(LOG_AUTH)
42 #define LOG_AUTHPRIV LOG_AUTH
51 syslog_ntoa(const char *s
)
53 #define syslog_symbol(a) #a, a
54 static syslog_symbol_t symbols
[] = {
56 {syslog_symbol(LOG_AUTHPRIV
)},
59 {syslog_symbol(LOG_DAEMON
)},
62 {syslog_symbol(LOG_LOCAL0
)},
65 {syslog_symbol(LOG_LOCAL1
)},
68 {syslog_symbol(LOG_LOCAL2
)},
71 {syslog_symbol(LOG_LOCAL3
)},
74 {syslog_symbol(LOG_LOCAL4
)},
77 {syslog_symbol(LOG_LOCAL5
)},
80 {syslog_symbol(LOG_LOCAL6
)},
83 {syslog_symbol(LOG_LOCAL7
)},
86 {syslog_symbol(LOG_USER
)},
89 {syslog_symbol(LOG_ERR
)},
92 {syslog_symbol(LOG_WARNING
)},
95 {syslog_symbol(LOG_NOTICE
)},
98 {syslog_symbol(LOG_INFO
)},
101 {syslog_symbol(LOG_DEBUG
)},
107 for (p
= symbols
; p
->name
!= NULL
; ++p
)
108 if (!strcmp(s
, p
->name
) || !strcasecmp(s
, p
->name
+ 4))
111 debugs(1, 1, "Unknown syslog facility/priority '" << s
<< "'");
119 #define PRIORITY_MASK (LOG_ERR | LOG_WARNING | LOG_NOTICE | LOG_INFO | LOG_DEBUG)
122 logfile_mod_syslog_writeline(Logfile
* lf
, const char *buf
, size_t len
)
124 l_syslog_t
*ll
= (l_syslog_t
*) lf
->data
;
125 syslog(ll
->syslog_priority
, "%s", (char *) buf
);
129 logfile_mod_syslog_linestart(Logfile
* lf
)
134 logfile_mod_syslog_lineend(Logfile
* lf
)
139 logfile_mod_syslog_flush(Logfile
* lf
)
144 logfile_mod_syslog_rotate(Logfile
* lf
)
149 logfile_mod_syslog_close(Logfile
* lf
)
158 * This code expects the path to be syslog:<priority>
161 logfile_mod_syslog_open(Logfile
* lf
, const char *path
, size_t bufsz
, int fatal_flag
)
163 lf
->f_close
= logfile_mod_syslog_close
;
164 lf
->f_linewrite
= logfile_mod_syslog_writeline
;
165 lf
->f_linestart
= logfile_mod_syslog_linestart
;
166 lf
->f_lineend
= logfile_mod_syslog_lineend
;
167 lf
->f_flush
= logfile_mod_syslog_flush
;
168 lf
->f_rotate
= logfile_mod_syslog_rotate
;
170 l_syslog_t
*ll
= static_cast<l_syslog_t
*>(xcalloc(1, sizeof(*ll
)));
173 ll
->syslog_priority
= LOG_INFO
;
175 if (path
[6] != '\0') {
176 char *priority
= xstrdup(path
);
177 char *facility
= (char *) strchr(priority
, '.');
179 facility
= (char *) strchr(priority
, '|');
183 ll
->syslog_priority
|= syslog_ntoa(facility
);
185 ll
->syslog_priority
|= syslog_ntoa(priority
);
187 if ((ll
->syslog_priority
& PRIORITY_MASK
) == 0)
188 ll
->syslog_priority
|= LOG_INFO
;