1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2010 Mark Atwood
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 2 of the License.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30
# define SYSLOG_NAMES 1
34
WrapSyslog::WrapSyslog () :
38
WrapSyslog::~WrapSyslog ()
41
delete &(WrapSyslog::singleton());
44
WrapSyslog& WrapSyslog::singleton()
46
static WrapSyslog *handle = new WrapSyslog();
50
/* TODO, for the sake of performance, scan through all the priority
51
and facility names, and construct a stl hash, minimal perfect hash,
52
or some other high performance read data structure. This can even
53
be done at compile time. */
55
int WrapSyslog::getPriorityByName(const char *priority_name)
57
for (int ndx= 0; prioritynames[ndx].c_name; ndx++)
59
if (strcasecmp(prioritynames[ndx].c_name, priority_name) == 0)
61
return prioritynames[ndx].c_val;
64
// no matching priority found
68
int WrapSyslog::getFacilityByName(const char *facility_name)
70
for (int ndx= 0; facilitynames[ndx].c_name; ndx++)
72
if (strcasecmp(facilitynames[ndx].c_name, facility_name) == 0)
74
return facilitynames[ndx].c_val;
77
// no matching facility found
81
void WrapSyslog::openlog(char *ident)
83
if (openlog_check == false)
85
memset(openlog_ident, 0, sizeof(openlog_ident));
86
strncpy(openlog_ident, ident, sizeof(openlog_ident)-1);
87
::openlog(openlog_ident, LOG_PID, LOG_USER);
92
void WrapSyslog::vlog(int facility, int priority, const char *format, va_list ap)
94
assert(openlog_check == true);
95
vsyslog(facility | priority, format, ap);
98
void WrapSyslog::log (int facility, int priority, const char *format, ...)
100
assert(openlog_check == true);
102
va_start(ap, format);
103
vsyslog(facility | priority, format, ap);