2 * Copyright (C) 2004-2007, 2009 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1999-2002 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: log.c,v 1.46.334.3 2009/01/07 01:50:14 jinmei 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 },
47 { "query-errors", 0 },
52 * When adding a new module, be sure to add the appropriate
53 * \#define to <dns/log.h>.
55 static isc_logmodule_t modules[] = {
60 { "interfacemgr", 0 },
71 ns_log_init(isc_boolean_t safe) {
73 isc_logconfig_t *lcfg = NULL;
75 ns_g_categories = categories;
76 ns_g_modules = modules;
79 * Setup a logging context.
81 result = isc_log_create(ns_g_mctx, &ns_g_lctx, &lcfg);
82 if (result != ISC_R_SUCCESS)
86 * named-checktool.c:setup_logging() needs to be kept in sync.
88 isc_log_registercategories(ns_g_lctx, ns_g_categories);
89 isc_log_registermodules(ns_g_lctx, ns_g_modules);
90 isc_log_setcontext(ns_g_lctx);
91 dns_log_init(ns_g_lctx);
92 dns_log_setcontext(ns_g_lctx);
93 cfg_log_init(ns_g_lctx);
96 result = ns_log_setsafechannels(lcfg);
98 result = ns_log_setdefaultchannels(lcfg);
99 if (result != ISC_R_SUCCESS)
102 result = ns_log_setdefaultcategory(lcfg);
103 if (result != ISC_R_SUCCESS)
106 return (ISC_R_SUCCESS);
109 isc_log_destroy(&ns_g_lctx);
110 isc_log_setcontext(NULL);
111 dns_log_setcontext(NULL);
117 ns_log_setdefaultchannels(isc_logconfig_t *lcfg) {
119 isc_logdestination_t destination;
122 * By default, the logging library makes "default_debug" log to
123 * stderr. In BIND, we want to override this and log to named.run
124 * instead, unless the -g option was given.
126 if (! ns_g_logstderr) {
127 destination.file.stream = NULL;
128 destination.file.name = "named.run";
129 destination.file.versions = ISC_LOG_ROLLNEVER;
130 destination.file.maximum_size = 0;
131 result = isc_log_createchannel(lcfg, "default_debug",
137 if (result != ISC_R_SUCCESS)
141 #if ISC_FACILITY != LOG_DAEMON
142 destination.facility = ISC_FACILITY;
143 result = isc_log_createchannel(lcfg, "default_syslog",
144 ISC_LOG_TOSYSLOG, ISC_LOG_INFO,
146 if (result != ISC_R_SUCCESS)
151 * Set the initial debug level.
153 isc_log_setdebuglevel(ns_g_lctx, ns_g_debuglevel);
155 result = ISC_R_SUCCESS;
162 ns_log_setsafechannels(isc_logconfig_t *lcfg) {
164 #if ISC_FACILITY != LOG_DAEMON
165 isc_logdestination_t destination;
168 if (! ns_g_logstderr) {
169 result = isc_log_createchannel(lcfg, "default_debug",
173 if (result != ISC_R_SUCCESS)
177 * Setting the debug level to zero should get the output
178 * discarded a bit faster.
180 isc_log_setdebuglevel(ns_g_lctx, 0);
182 isc_log_setdebuglevel(ns_g_lctx, ns_g_debuglevel);
185 #if ISC_FACILITY != LOG_DAEMON
186 destination.facility = ISC_FACILITY;
187 result = isc_log_createchannel(lcfg, "default_syslog",
188 ISC_LOG_TOSYSLOG, ISC_LOG_INFO,
190 if (result != ISC_R_SUCCESS)
194 result = ISC_R_SUCCESS;
201 ns_log_setdefaultcategory(isc_logconfig_t *lcfg) {
204 if (! ns_g_logstderr) {
205 result = isc_log_usechannel(lcfg, "default_syslog",
206 ISC_LOGCATEGORY_DEFAULT, NULL);
207 if (result != ISC_R_SUCCESS)
211 result = isc_log_usechannel(lcfg, "default_debug",
212 ISC_LOGCATEGORY_DEFAULT, NULL);
213 if (result != ISC_R_SUCCESS)
216 result = ISC_R_SUCCESS;
223 ns_log_setunmatchedcategory(isc_logconfig_t *lcfg) {
226 result = isc_log_usechannel(lcfg, "null",
227 NS_LOGCATEGORY_UNMATCHED, NULL);
232 ns_log_shutdown(void) {
233 isc_log_destroy(&ns_g_lctx);
234 isc_log_setcontext(NULL);
235 dns_log_setcontext(NULL);