2 * Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1999-2001 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.2 2004/03/09 06:09:18 marka Exp $ */
22 #include <isc/result.h>
24 #include <isccfg/log.h>
26 #include <named/log.h>
29 * When adding a new category, be sure to add the appropriate
30 * #define to <named/log.h>.
32 static isc_logcategory_t categories[] = {
43 * When adding a new module, be sure to add the appropriate
44 * #define to <dns/log.h>.
46 static isc_logmodule_t modules[] = {
51 { "interfacemgr", 0 },
62 ns_log_init(isc_boolean_t safe) {
64 isc_logconfig_t *lcfg = NULL;
66 ns_g_categories = categories;
67 ns_g_modules = modules;
70 * Setup a logging context.
72 result = isc_log_create(ns_g_mctx, &ns_g_lctx, &lcfg);
73 if (result != ISC_R_SUCCESS)
76 isc_log_registercategories(ns_g_lctx, ns_g_categories);
77 isc_log_registermodules(ns_g_lctx, ns_g_modules);
78 isc_log_setcontext(ns_g_lctx);
79 dns_log_init(ns_g_lctx);
80 dns_log_setcontext(ns_g_lctx);
81 cfg_log_init(ns_g_lctx);
84 result = ns_log_setsafechannels(lcfg);
86 result = ns_log_setdefaultchannels(lcfg);
87 if (result != ISC_R_SUCCESS)
90 result = ns_log_setdefaultcategory(lcfg);
91 if (result != ISC_R_SUCCESS)
94 return (ISC_R_SUCCESS);
97 isc_log_destroy(&ns_g_lctx);
98 isc_log_setcontext(NULL);
99 dns_log_setcontext(NULL);
105 ns_log_setdefaultchannels(isc_logconfig_t *lcfg) {
107 isc_logdestination_t destination;
110 * By default, the logging library makes "default_debug" log to
111 * stderr. In BIND, we want to override this and log to named.run
112 * instead, unless the the -g option was given.
114 if (! ns_g_logstderr) {
115 destination.file.stream = NULL;
116 destination.file.name = "named.run";
117 destination.file.versions = ISC_LOG_ROLLNEVER;
118 destination.file.maximum_size = 0;
119 result = isc_log_createchannel(lcfg, "default_debug",
125 if (result != ISC_R_SUCCESS)
130 * Set the initial debug level.
132 isc_log_setdebuglevel(ns_g_lctx, ns_g_debuglevel);
134 result = ISC_R_SUCCESS;
141 ns_log_setsafechannels(isc_logconfig_t *lcfg) {
144 if (! ns_g_logstderr) {
145 result = isc_log_createchannel(lcfg, "default_debug",
149 if (result != ISC_R_SUCCESS)
153 * Setting the debug level to zero should get the output
154 * discarded a bit faster.
156 isc_log_setdebuglevel(ns_g_lctx, 0);
158 isc_log_setdebuglevel(ns_g_lctx, ns_g_debuglevel);
161 result = ISC_R_SUCCESS;
168 ns_log_setdefaultcategory(isc_logconfig_t *lcfg) {
171 if (! ns_g_logstderr) {
172 result = isc_log_usechannel(lcfg, "default_syslog",
173 ISC_LOGCATEGORY_DEFAULT, NULL);
174 if (result != ISC_R_SUCCESS)
178 result = isc_log_usechannel(lcfg, "default_debug",
179 ISC_LOGCATEGORY_DEFAULT, NULL);
180 if (result != ISC_R_SUCCESS)
183 result = ISC_R_SUCCESS;
190 ns_log_setunmatchedcategory(isc_logconfig_t *lcfg) {
193 result = isc_log_usechannel(lcfg, "null",
194 NS_LOGCATEGORY_UNMATCHED, NULL);
199 ns_log_shutdown(void) {
200 isc_log_destroy(&ns_g_lctx);
201 isc_log_setcontext(NULL);
202 dns_log_setcontext(NULL);