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.
39 #include "log/ModSyslog.h"
41 /* Define LOG_AUTHPRIV as LOG_AUTH on systems still using the old deprecated LOG_AUTH */
42 #if !defined(LOG_AUTHPRIV) && defined(LOG_AUTH)
43 #define LOG_AUTHPRIV LOG_AUTH
52 syslog_ntoa(const char *s
)
54 #define syslog_symbol(a) #a, a
55 static syslog_symbol_t symbols
[] = {
57 {syslog_symbol(LOG_AUTHPRIV
)},
60 {syslog_symbol(LOG_DAEMON
)},
63 {syslog_symbol(LOG_LOCAL0
)},
66 {syslog_symbol(LOG_LOCAL1
)},
69 {syslog_symbol(LOG_LOCAL2
)},
72 {syslog_symbol(LOG_LOCAL3
)},
75 {syslog_symbol(LOG_LOCAL4
)},
78 {syslog_symbol(LOG_LOCAL5
)},
81 {syslog_symbol(LOG_LOCAL6
)},
84 {syslog_symbol(LOG_LOCAL7
)},
87 {syslog_symbol(LOG_USER
)},
90 {syslog_symbol(LOG_ERR
)},
93 {syslog_symbol(LOG_WARNING
)},
96 {syslog_symbol(LOG_NOTICE
)},
99 {syslog_symbol(LOG_INFO
)},
102 {syslog_symbol(LOG_DEBUG
)},
108 for (p
= symbols
; p
->name
!= NULL
; ++p
)
109 if (!strcmp(s
, p
->name
) || !strcasecmp(s
, p
->name
+ 4))
112 debugs(1, DBG_IMPORTANT
, "Unknown syslog facility/priority '" << s
<< "'");
120 #define PRIORITY_MASK (LOG_ERR | LOG_WARNING | LOG_NOTICE | LOG_INFO | LOG_DEBUG)
123 logfile_mod_syslog_writeline(Logfile
* lf
, const char *buf
, size_t len
)
125 l_syslog_t
*ll
= (l_syslog_t
*) lf
->data
;
126 syslog(ll
->syslog_priority
, "%s", (char *) buf
);
130 logfile_mod_syslog_linestart(Logfile
* lf
)
135 logfile_mod_syslog_lineend(Logfile
* lf
)
140 logfile_mod_syslog_flush(Logfile
* lf
)
145 logfile_mod_syslog_rotate(Logfile
* lf
)
150 logfile_mod_syslog_close(Logfile
* lf
)
159 * This code expects the path to be syslog:<priority>
162 logfile_mod_syslog_open(Logfile
* lf
, const char *path
, size_t bufsz
, int fatal_flag
)
164 lf
->f_close
= logfile_mod_syslog_close
;
165 lf
->f_linewrite
= logfile_mod_syslog_writeline
;
166 lf
->f_linestart
= logfile_mod_syslog_linestart
;
167 lf
->f_lineend
= logfile_mod_syslog_lineend
;
168 lf
->f_flush
= logfile_mod_syslog_flush
;
169 lf
->f_rotate
= logfile_mod_syslog_rotate
;
171 l_syslog_t
*ll
= static_cast<l_syslog_t
*>(xcalloc(1, sizeof(*ll
)));
174 ll
->syslog_priority
= LOG_INFO
;
176 if (path
[6] != '\0') {
177 char *priority
= xstrdup(path
);
178 char *facility
= (char *) strchr(priority
, '.');
180 facility
= (char *) strchr(priority
, '|');
184 ll
->syslog_priority
|= syslog_ntoa(facility
);
186 ll
->syslog_priority
|= syslog_ntoa(priority
);
188 if ((ll
->syslog_priority
& PRIORITY_MASK
) == 0)
189 ll
->syslog_priority
|= LOG_INFO
;