4 * Copyright (C) 2004, 2007 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 2001-2003 Internet Software Consortium.
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
20 /* Id: syslog.c,v 1.10 2007/06/19 23:47:19 tbox Exp */
30 #include <isc/bindevt.h>
31 #include <isc/result.h>
32 #include <isc/syslog.h>
35 static HANDLE hAppLog
= NULL
;
36 static FILE *log_stream
;
37 static int debug_level
= 0;
39 static struct dsn_c_pvt_sfnt
{
46 { LOG_DAEMON
, "daemon" },
48 { LOG_SYSLOG
, "syslog" },
60 { LOG_AUTHPRIV
, "authpriv" },
65 { LOG_LOCAL0
, "local0"},
66 { LOG_LOCAL1
, "local1"},
67 { LOG_LOCAL2
, "local2"},
68 { LOG_LOCAL3
, "local3"},
69 { LOG_LOCAL4
, "local4"},
70 { LOG_LOCAL5
, "local5"},
71 { LOG_LOCAL6
, "local6"},
72 { LOG_LOCAL7
, "local7"},
77 isc_syslog_facilityfromstring(const char *str
, int *facilityp
) {
81 REQUIRE(facilityp
!= NULL
);
83 for (i
= 0; facilities
[i
].strval
!= NULL
; i
++) {
84 if (strcasecmp(facilities
[i
].strval
, str
) == 0) {
85 *facilityp
= facilities
[i
].val
;
86 return (ISC_R_SUCCESS
);
89 return (ISC_R_NOTFOUND
);
93 * Log to the NT Event Log
96 syslog(int level
, const char *fmt
, ...) {
104 vsprintf(buf
, fmt
, ap
);
107 /* Make sure that the channel is open to write the event */
108 if (hAppLog
!= NULL
) {
113 ReportEvent(hAppLog
, EVENTLOG_INFORMATION_TYPE
, 0,
114 BIND_INFO_MSG
, NULL
, 1, 0, str
, NULL
);
117 ReportEvent(hAppLog
, EVENTLOG_WARNING_TYPE
, 0,
118 BIND_WARN_MSG
, NULL
, 1, 0, str
, NULL
);
121 ReportEvent(hAppLog
, EVENTLOG_ERROR_TYPE
, 0,
122 BIND_ERR_MSG
, NULL
, 1, 0, str
, NULL
);
129 * Initialize event logging
132 openlog(const char *name
, int flags
, ...) {
133 /* Get a handle to the Application event log */
134 hAppLog
= RegisterEventSource(NULL
, name
);
138 * Close the Handle to the application Event Log
139 * We don't care whether or not we succeeded so ignore return values
140 * In fact if we failed then we would have nowhere to put the message
144 DeregisterEventSource(hAppLog
);
148 * Keep event logging synced with the current debug level
151 ModifyLogLevel(int level
) {
156 * Initialize logging for the port section of libbind.
157 * Piggyback onto stream given.
160 InitNTLogging(FILE *stream
, int debug
) {
162 ModifyLogLevel(debug
);
165 * This function is for reporting errors to the application
166 * event log in case the regular syslog is not available
167 * mainly during startup. It should not be used under normal
171 NTReportError(const char *name
, const char *str
) {
172 HANDLE hNTAppLog
= NULL
;
177 hNTAppLog
= RegisterEventSource(NULL
, name
);
179 ReportEvent(hNTAppLog
, EVENTLOG_ERROR_TYPE
, 0,
180 BIND_ERR_MSG
, NULL
, 1, 0, buf
, NULL
);
182 DeregisterEventSource(hNTAppLog
);