2 * Copyright (C) 2004, 2007 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 2001-2003 Internet Software Consortium.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 * PERFORMANCE OF THIS SOFTWARE.
18 /* $Id: syslog.c,v 1.10 2007/06/19 23:47:19 tbox Exp $ */
28 #include <isc/bindevt.h>
29 #include <isc/result.h>
30 #include <isc/syslog.h>
33 static HANDLE hAppLog = NULL;
34 static FILE *log_stream;
35 static int debug_level = 0;
37 static struct dsn_c_pvt_sfnt {
44 { LOG_DAEMON, "daemon" },
46 { LOG_SYSLOG, "syslog" },
58 { LOG_AUTHPRIV, "authpriv" },
63 { LOG_LOCAL0, "local0"},
64 { LOG_LOCAL1, "local1"},
65 { LOG_LOCAL2, "local2"},
66 { LOG_LOCAL3, "local3"},
67 { LOG_LOCAL4, "local4"},
68 { LOG_LOCAL5, "local5"},
69 { LOG_LOCAL6, "local6"},
70 { LOG_LOCAL7, "local7"},
75 isc_syslog_facilityfromstring(const char *str, int *facilityp) {
79 REQUIRE(facilityp != NULL);
81 for (i = 0; facilities[i].strval != NULL; i++) {
82 if (strcasecmp(facilities[i].strval, str) == 0) {
83 *facilityp = facilities[i].val;
84 return (ISC_R_SUCCESS);
87 return (ISC_R_NOTFOUND);
91 * Log to the NT Event Log
94 syslog(int level, const char *fmt, ...) {
102 vsprintf(buf, fmt, ap);
105 /* Make sure that the channel is open to write the event */
106 if (hAppLog != NULL) {
111 ReportEvent(hAppLog, EVENTLOG_INFORMATION_TYPE, 0,
112 BIND_INFO_MSG, NULL, 1, 0, str, NULL);
115 ReportEvent(hAppLog, EVENTLOG_WARNING_TYPE, 0,
116 BIND_WARN_MSG, NULL, 1, 0, str, NULL);
119 ReportEvent(hAppLog, EVENTLOG_ERROR_TYPE, 0,
120 BIND_ERR_MSG, NULL, 1, 0, str, NULL);
127 * Initialize event logging
130 openlog(const char *name, int flags, ...) {
131 /* Get a handle to the Application event log */
132 hAppLog = RegisterEventSource(NULL, name);
136 * Close the Handle to the application Event Log
137 * We don't care whether or not we succeeded so ignore return values
138 * In fact if we failed then we would have nowhere to put the message
142 DeregisterEventSource(hAppLog);
146 * Keep event logging synced with the current debug level
149 ModifyLogLevel(int level) {
154 * Initialize logging for the port section of libbind.
155 * Piggyback onto stream given.
158 InitNTLogging(FILE *stream, int debug) {
160 ModifyLogLevel(debug);
163 * This function is for reporting errors to the application
164 * event log in case the regular syslog is not available
165 * mainly during startup. It should not be used under normal
169 NTReportError(const char *name, const char *str) {
170 HANDLE hNTAppLog = NULL;
175 hNTAppLog = RegisterEventSource(NULL, name);
177 ReportEvent(hNTAppLog, EVENTLOG_ERROR_TYPE, 0,
178 BIND_ERR_MSG, NULL, 1, 0, buf, NULL);
180 DeregisterEventSource(hNTAppLog);