2 * Copyright (C) 2004-2006 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1999-2002 Internet Software Consortium.
5 * Permission to use, copy, modify, and 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: log.c,v 1.37.18.6 2006/06/09 00:54:08 marka Exp $ */
24 #include <isc/result.h>
26 #include <isccfg/log.h>
28 #include <named/log.h>
31 #define ISC_FACILITY LOG_DAEMON
35 * When adding a new category, be sure to add the appropriate
36 * #define to <named/log.h> and to update the list in
37 * bin/check/check-tool.c.
39 static isc_logcategory_t categories
[] = {
46 { "update-security", 0 },
51 * When adding a new module, be sure to add the appropriate
52 * #define to <dns/log.h>.
54 static isc_logmodule_t modules
[] = {
59 { "interfacemgr", 0 },
70 ns_log_init(isc_boolean_t safe
) {
72 isc_logconfig_t
*lcfg
= NULL
;
74 ns_g_categories
= categories
;
75 ns_g_modules
= modules
;
78 * Setup a logging context.
80 result
= isc_log_create(ns_g_mctx
, &ns_g_lctx
, &lcfg
);
81 if (result
!= ISC_R_SUCCESS
)
85 * named-checktool.c:setup_logging() needs to be kept in sync.
87 isc_log_registercategories(ns_g_lctx
, ns_g_categories
);
88 isc_log_registermodules(ns_g_lctx
, ns_g_modules
);
89 isc_log_setcontext(ns_g_lctx
);
90 dns_log_init(ns_g_lctx
);
91 dns_log_setcontext(ns_g_lctx
);
92 cfg_log_init(ns_g_lctx
);
95 result
= ns_log_setsafechannels(lcfg
);
97 result
= ns_log_setdefaultchannels(lcfg
);
98 if (result
!= ISC_R_SUCCESS
)
101 result
= ns_log_setdefaultcategory(lcfg
);
102 if (result
!= ISC_R_SUCCESS
)
105 return (ISC_R_SUCCESS
);
108 isc_log_destroy(&ns_g_lctx
);
109 isc_log_setcontext(NULL
);
110 dns_log_setcontext(NULL
);
116 ns_log_setdefaultchannels(isc_logconfig_t
*lcfg
) {
118 isc_logdestination_t destination
;
121 * By default, the logging library makes "default_debug" log to
122 * stderr. In BIND, we want to override this and log to named.run
123 * instead, unless the the -g option was given.
125 if (! ns_g_logstderr
) {
126 destination
.file
.stream
= NULL
;
127 destination
.file
.name
= "named.run";
128 destination
.file
.versions
= ISC_LOG_ROLLNEVER
;
129 destination
.file
.maximum_size
= 0;
130 result
= isc_log_createchannel(lcfg
, "default_debug",
136 if (result
!= ISC_R_SUCCESS
)
140 #if ISC_FACILITY != LOG_DAEMON
141 destination
.facility
= ISC_FACILITY
;
142 result
= isc_log_createchannel(lcfg
, "default_syslog",
143 ISC_LOG_TOSYSLOG
, ISC_LOG_INFO
,
145 if (result
!= ISC_R_SUCCESS
)
150 * Set the initial debug level.
152 isc_log_setdebuglevel(ns_g_lctx
, ns_g_debuglevel
);
154 result
= ISC_R_SUCCESS
;
161 ns_log_setsafechannels(isc_logconfig_t
*lcfg
) {
163 #if ISC_FACILITY != LOG_DAEMON
164 isc_logdestination_t destination
;
167 if (! ns_g_logstderr
) {
168 result
= isc_log_createchannel(lcfg
, "default_debug",
172 if (result
!= ISC_R_SUCCESS
)
176 * Setting the debug level to zero should get the output
177 * discarded a bit faster.
179 isc_log_setdebuglevel(ns_g_lctx
, 0);
181 isc_log_setdebuglevel(ns_g_lctx
, ns_g_debuglevel
);
184 #if ISC_FACILITY != LOG_DAEMON
185 destination
.facility
= ISC_FACILITY
;
186 result
= isc_log_createchannel(lcfg
, "default_syslog",
187 ISC_LOG_TOSYSLOG
, ISC_LOG_INFO
,
189 if (result
!= ISC_R_SUCCESS
)
193 result
= ISC_R_SUCCESS
;
200 ns_log_setdefaultcategory(isc_logconfig_t
*lcfg
) {
203 if (! ns_g_logstderr
) {
204 result
= isc_log_usechannel(lcfg
, "default_syslog",
205 ISC_LOGCATEGORY_DEFAULT
, NULL
);
206 if (result
!= ISC_R_SUCCESS
)
210 result
= isc_log_usechannel(lcfg
, "default_debug",
211 ISC_LOGCATEGORY_DEFAULT
, NULL
);
212 if (result
!= ISC_R_SUCCESS
)
215 result
= ISC_R_SUCCESS
;
222 ns_log_setunmatchedcategory(isc_logconfig_t
*lcfg
) {
225 result
= isc_log_usechannel(lcfg
, "null",
226 NS_LOGCATEGORY_UNMATCHED
, NULL
);
231 ns_log_shutdown(void) {
232 isc_log_destroy(&ns_g_lctx
);
233 isc_log_setcontext(NULL
);
234 dns_log_setcontext(NULL
);