]> git.ipfire.org Git - thirdparty/squid.git/blame - src/log/ModSyslog.cc
Author: Adrian Chadd + Tim Starling
[thirdparty/squid.git] / src / log / ModSyslog.cc
CommitLineData
82b7abe3
AJ
1/*
2 * DEBUG: section 50 Log file handling
3 * AUTHOR: Duane Wessels
4 *
5 * SQUID Web Proxy Cache http://www.squid-cache.org/
6 * ----------------------------------------------------------
7 *
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.
16 *
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.
21 *
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.
26 *
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.
30 *
31 */
32
33#include "squid.h"
34
35#if HAVE_SYSLOG
36
37#include "log/File.h"
38#include "log/ModSyslog.h"
39
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
43#endif
44
45typedef struct {
46 const char *name;
47 int value;
48} syslog_symbol_t;
49
50static int
51syslog_ntoa(const char *s)
52{
53#define syslog_symbol(a) #a, a
54 static syslog_symbol_t symbols[] =
55 {
56#ifdef LOG_AUTHPRIV
57 {syslog_symbol(LOG_AUTHPRIV)},
58#endif
59#ifdef LOG_DAEMON
60 {syslog_symbol(LOG_DAEMON)},
61#endif
62#ifdef LOG_LOCAL0
63 {syslog_symbol(LOG_LOCAL0)},
64#endif
65#ifdef LOG_LOCAL1
66 {syslog_symbol(LOG_LOCAL1)},
67#endif
68#ifdef LOG_LOCAL2
69 {syslog_symbol(LOG_LOCAL2)},
70#endif
71#ifdef LOG_LOCAL3
72 {syslog_symbol(LOG_LOCAL3)},
73#endif
74#ifdef LOG_LOCAL4
75 {syslog_symbol(LOG_LOCAL4)},
76#endif
77#ifdef LOG_LOCAL5
78 {syslog_symbol(LOG_LOCAL5)},
79#endif
80#ifdef LOG_LOCAL6
81 {syslog_symbol(LOG_LOCAL6)},
82#endif
83#ifdef LOG_LOCAL7
84 {syslog_symbol(LOG_LOCAL7)},
85#endif
86#ifdef LOG_USER
87 {syslog_symbol(LOG_USER)},
88#endif
89#ifdef LOG_ERR
90 {syslog_symbol(LOG_ERR)},
91#endif
92#ifdef LOG_WARNING
93 {syslog_symbol(LOG_WARNING)},
94#endif
95#ifdef LOG_NOTICE
96 {syslog_symbol(LOG_NOTICE)},
97#endif
98#ifdef LOG_INFO
99 {syslog_symbol(LOG_INFO)},
100#endif
101#ifdef LOG_DEBUG
102 {syslog_symbol(LOG_DEBUG)},
103#endif
104 {NULL, 0}
105 };
106 syslog_symbol_t *p;
107
108 for (p = symbols; p->name != NULL; ++p)
109 if (!strcmp(s, p->name) || !strcasecmp(s, p->name + 4))
110 return p->value;
111
112 debugs(1, 1, "Unknown syslog facility/priority '" << s << "'");
113 return 0;
114}
115
116typedef struct {
117 int syslog_priority;
118} l_syslog_t;
119
120#define PRIORITY_MASK (LOG_ERR | LOG_WARNING | LOG_NOTICE | LOG_INFO | LOG_DEBUG)
121
122static void
123logfile_mod_syslog_writeline(Logfile * lf, const char *buf, size_t len)
124{
125 l_syslog_t *ll = (l_syslog_t *) lf->data;
126 syslog(ll->syslog_priority, "%s", (char *) buf);
127}
128
129static void
130logfile_mod_syslog_linestart(Logfile * lf)
131{
132}
133
134static void
135logfile_mod_syslog_lineend(Logfile * lf)
136{
137}
138
139static void
140logfile_mod_syslog_flush(Logfile * lf)
141{
142}
143
144static void
145logfile_mod_syslog_rotate(Logfile * lf)
146{
147}
148
149static void
150logfile_mod_syslog_close(Logfile * lf)
151{
152 xfree(lf->data);
153 lf->data = NULL;
154}
155
156
157
158/*
159 * This code expects the path to be syslog:<priority>
160 */
161int
162logfile_mod_syslog_open(Logfile * lf, const char *path, size_t bufsz, int fatal_flag)
163{
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;
170
171 l_syslog_t *ll = static_cast<l_syslog_t*>(xcalloc(1, sizeof(*ll)));
172 lf->data = ll;
173
174 ll->syslog_priority = LOG_INFO;
175
176 if (path[6] != '\0') {
177 char *priority = xstrdup(path);
178 char *facility = (char *) strchr(priority, '.');
179 if (!facility)
180 facility = (char *) strchr(priority, '|');
181 if (facility) {
182 *facility++ = '\0';
183 ll->syslog_priority |= syslog_ntoa(facility);
184 }
185 ll->syslog_priority |= syslog_ntoa(priority);
186 xfree(priority);
187 if ((ll->syslog_priority & PRIORITY_MASK) == 0)
188 ll->syslog_priority |= LOG_INFO;
189 }
190
191 return 1;
192}
193#endif