1 /* $NetBSD: log.c,v 1.5 2014/12/10 04:37:51 christos Exp $ */
4 * Copyright (C) 2004-2007, 2009, 2013 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 1999-2002 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: log.c,v 1.49 2009/01/07 01:46:40 jinmei Exp */
26 #include <isc/result.h>
28 #include <isccfg/log.h>
30 #include <named/log.h>
33 #define ISC_FACILITY LOG_DAEMON
37 * When adding a new category, be sure to add the appropriate
38 * \#define to <named/log.h> and to update the list in
39 * bin/check/check-tool.c.
41 static isc_logcategory_t categories
[] = {
48 { "update-security", 0 },
49 { "query-errors", 0 },
54 * When adding a new module, be sure to add the appropriate
55 * \#define to <dns/log.h>.
57 static isc_logmodule_t modules
[] = {
62 { "interfacemgr", 0 },
73 ns_log_init(isc_boolean_t safe
) {
75 isc_logconfig_t
*lcfg
= NULL
;
77 ns_g_categories
= categories
;
78 ns_g_modules
= modules
;
81 * Setup a logging context.
83 result
= isc_log_create(ns_g_mctx
, &ns_g_lctx
, &lcfg
);
84 if (result
!= ISC_R_SUCCESS
)
88 * named-checktool.c:setup_logging() needs to be kept in sync.
90 isc_log_registercategories(ns_g_lctx
, ns_g_categories
);
91 isc_log_registermodules(ns_g_lctx
, ns_g_modules
);
92 isc_log_setcontext(ns_g_lctx
);
93 dns_log_init(ns_g_lctx
);
94 dns_log_setcontext(ns_g_lctx
);
95 cfg_log_init(ns_g_lctx
);
98 result
= ns_log_setsafechannels(lcfg
);
100 result
= ns_log_setdefaultchannels(lcfg
);
101 if (result
!= ISC_R_SUCCESS
)
104 result
= ns_log_setdefaultcategory(lcfg
);
105 if (result
!= ISC_R_SUCCESS
)
108 return (ISC_R_SUCCESS
);
111 isc_log_destroy(&ns_g_lctx
);
112 isc_log_setcontext(NULL
);
113 dns_log_setcontext(NULL
);
119 ns_log_setdefaultchannels(isc_logconfig_t
*lcfg
) {
121 isc_logdestination_t destination
;
124 * By default, the logging library makes "default_debug" log to
125 * stderr. In BIND, we want to override this and log to named.run
126 * instead, unless the -g option was given.
128 if (! ns_g_logstderr
) {
129 destination
.file
.stream
= NULL
;
130 destination
.file
.name
= "named.run";
131 destination
.file
.versions
= ISC_LOG_ROLLNEVER
;
132 destination
.file
.maximum_size
= 0;
133 result
= isc_log_createchannel(lcfg
, "default_debug",
139 if (result
!= ISC_R_SUCCESS
)
143 #if ISC_FACILITY != LOG_DAEMON
144 destination
.facility
= ISC_FACILITY
;
145 result
= isc_log_createchannel(lcfg
, "default_syslog",
146 ISC_LOG_TOSYSLOG
, ISC_LOG_INFO
,
148 if (result
!= ISC_R_SUCCESS
)
153 * Set the initial debug level.
155 isc_log_setdebuglevel(ns_g_lctx
, ns_g_debuglevel
);
157 result
= ISC_R_SUCCESS
;
164 ns_log_setsafechannels(isc_logconfig_t
*lcfg
) {
166 #if ISC_FACILITY != LOG_DAEMON
167 isc_logdestination_t destination
;
170 if (! ns_g_logstderr
) {
171 result
= isc_log_createchannel(lcfg
, "default_debug",
175 if (result
!= ISC_R_SUCCESS
)
179 * Setting the debug level to zero should get the output
180 * discarded a bit faster.
182 isc_log_setdebuglevel(ns_g_lctx
, 0);
184 isc_log_setdebuglevel(ns_g_lctx
, ns_g_debuglevel
);
187 #if ISC_FACILITY != LOG_DAEMON
188 destination
.facility
= ISC_FACILITY
;
189 result
= isc_log_createchannel(lcfg
, "default_syslog",
190 ISC_LOG_TOSYSLOG
, ISC_LOG_INFO
,
192 if (result
!= ISC_R_SUCCESS
)
196 result
= ISC_R_SUCCESS
;
203 ns_log_setdefaultcategory(isc_logconfig_t
*lcfg
) {
206 if (! ns_g_logstderr
&& ! ns_g_nosyslog
) {
207 result
= isc_log_usechannel(lcfg
, "default_syslog",
208 ISC_LOGCATEGORY_DEFAULT
, NULL
);
209 if (result
!= ISC_R_SUCCESS
)
213 result
= isc_log_usechannel(lcfg
, "default_debug",
214 ISC_LOGCATEGORY_DEFAULT
, NULL
);
215 if (result
!= ISC_R_SUCCESS
)
218 result
= ISC_R_SUCCESS
;
225 ns_log_setunmatchedcategory(isc_logconfig_t
*lcfg
) {
228 result
= isc_log_usechannel(lcfg
, "null",
229 NS_LOGCATEGORY_UNMATCHED
, NULL
);
234 ns_log_shutdown(void) {
235 isc_log_destroy(&ns_g_lctx
);
236 isc_log_setcontext(NULL
);
237 dns_log_setcontext(NULL
);