2 * Copyright (C) 2004, 2005 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.33.2.1.10.6 2005/05/24 23:58:17 marka Exp $ */
22 #include <isc/result.h>
24 #include <isccfg/log.h>
26 #include <named/log.h>
29 #define ISC_FACILITY LOG_DAEMON
33 * When adding a new category, be sure to add the appropriate
34 * #define to <named/log.h>.
36 static isc_logcategory_t categories[] = {
43 { "update-security", 0 },
48 * When adding a new module, be sure to add the appropriate
49 * #define to <dns/log.h>.
51 static isc_logmodule_t modules[] = {
56 { "interfacemgr", 0 },
67 ns_log_init(isc_boolean_t safe) {
69 isc_logconfig_t *lcfg = NULL;
71 ns_g_categories = categories;
72 ns_g_modules = modules;
75 * Setup a logging context.
77 result = isc_log_create(ns_g_mctx, &ns_g_lctx, &lcfg);
78 if (result != ISC_R_SUCCESS)
81 isc_log_registercategories(ns_g_lctx, ns_g_categories);
82 isc_log_registermodules(ns_g_lctx, ns_g_modules);
83 isc_log_setcontext(ns_g_lctx);
84 dns_log_init(ns_g_lctx);
85 dns_log_setcontext(ns_g_lctx);
86 cfg_log_init(ns_g_lctx);
89 result = ns_log_setsafechannels(lcfg);
91 result = ns_log_setdefaultchannels(lcfg);
92 if (result != ISC_R_SUCCESS)
95 result = ns_log_setdefaultcategory(lcfg);
96 if (result != ISC_R_SUCCESS)
99 return (ISC_R_SUCCESS);
102 isc_log_destroy(&ns_g_lctx);
103 isc_log_setcontext(NULL);
104 dns_log_setcontext(NULL);
110 ns_log_setdefaultchannels(isc_logconfig_t *lcfg) {
112 isc_logdestination_t destination;
115 * By default, the logging library makes "default_debug" log to
116 * stderr. In BIND, we want to override this and log to named.run
117 * instead, unless the the -g option was given.
119 if (! ns_g_logstderr) {
120 destination.file.stream = NULL;
121 destination.file.name = "named.run";
122 destination.file.versions = ISC_LOG_ROLLNEVER;
123 destination.file.maximum_size = 0;
124 result = isc_log_createchannel(lcfg, "default_debug",
130 if (result != ISC_R_SUCCESS)
134 #if ISC_FACILITY != LOG_DAEMON
135 destination.facility = ISC_FACILITY;
136 result = isc_log_createchannel(lcfg, "default_syslog",
137 ISC_LOG_TOSYSLOG, ISC_LOG_INFO,
139 if (result != ISC_R_SUCCESS)
144 * Set the initial debug level.
146 isc_log_setdebuglevel(ns_g_lctx, ns_g_debuglevel);
148 result = ISC_R_SUCCESS;
155 ns_log_setsafechannels(isc_logconfig_t *lcfg) {
157 #if ISC_FACILITY != LOG_DAEMON
158 isc_logdestination_t destination;
161 if (! ns_g_logstderr) {
162 result = isc_log_createchannel(lcfg, "default_debug",
166 if (result != ISC_R_SUCCESS)
170 * Setting the debug level to zero should get the output
171 * discarded a bit faster.
173 isc_log_setdebuglevel(ns_g_lctx, 0);
175 isc_log_setdebuglevel(ns_g_lctx, ns_g_debuglevel);
178 #if ISC_FACILITY != LOG_DAEMON
179 destination.facility = ISC_FACILITY;
180 result = isc_log_createchannel(lcfg, "default_syslog",
181 ISC_LOG_TOSYSLOG, ISC_LOG_INFO,
183 if (result != ISC_R_SUCCESS)
187 result = ISC_R_SUCCESS;
194 ns_log_setdefaultcategory(isc_logconfig_t *lcfg) {
197 if (! ns_g_logstderr) {
198 result = isc_log_usechannel(lcfg, "default_syslog",
199 ISC_LOGCATEGORY_DEFAULT, NULL);
200 if (result != ISC_R_SUCCESS)
204 result = isc_log_usechannel(lcfg, "default_debug",
205 ISC_LOGCATEGORY_DEFAULT, NULL);
206 if (result != ISC_R_SUCCESS)
209 result = ISC_R_SUCCESS;
216 ns_log_setunmatchedcategory(isc_logconfig_t *lcfg) {
219 result = isc_log_usechannel(lcfg, "null",
220 NS_LOGCATEGORY_UNMATCHED, NULL);
225 ns_log_shutdown(void) {
226 isc_log_destroy(&ns_g_lctx);
227 isc_log_setcontext(NULL);
228 dns_log_setcontext(NULL);