log.c 3.27 KB
Newer Older
Bob Halley's avatar
Bob Halley committed
1
/*
Bob Halley's avatar
Bob Halley committed
2
 * Copyright (C) 1999, 2000  Internet Software Consortium.
Bob Halley's avatar
Bob Halley committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
 * 
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
 * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
 * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
 * SOFTWARE.
 */

#include <config.h>

#include <isc/assertions.h>
#include <isc/log.h>
#include <isc/result.h>

#include <dns/log.h>

#include <named/globals.h>
#include <named/log.h>

/*
 * When adding a new category, be sure to add the appropriate
 * #define to <named/log.h>.
 */
static isc_logcategory_t categories[] = {
	{ "general",	 		0 },
	{ "client",	 		0 },
	{ "network",	 		0 },
37 38 39
	{ "update",	 		0 },
	{ "xfer-in",	 		0 },
	{ "xfer-out",	 		0 },
Mark Andrews's avatar
Mark Andrews committed
40
	{ "notify",	 		0 },
Bob Halley's avatar
Bob Halley committed
41 42 43 44 45 46 47 48 49 50 51 52 53
	{ NULL, 			0 }
};

/*
 * When adding a new module, be sure to add the appropriate
 * #define to <dns/log.h>.
 */
static isc_logmodule_t modules[] = {
	{ "main",	 		0 },
	{ "client",	 		0 },
	{ "server",		 	0 },
	{ "query",		 	0 },
	{ "interfacemgr",	 	0 },
54 55 56
	{ "update",	 		0 },
	{ "xfer-in",	 		0 },
	{ "xfer-out",	 		0 },
Mark Andrews's avatar
Mark Andrews committed
57
	{ "notify",	 		0 },
Bob Halley's avatar
Bob Halley committed
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
	{ NULL, 			0 }
};

isc_result_t
ns_log_init(void) {
	isc_result_t result;
	isc_logdestination_t destination;
	unsigned int flags;

	ns_g_categories = categories;
	ns_g_modules = modules;

	/*
	 * XXXRTH  This is not necessarily the final default logging
	 *         setup.
	 */

Bob Halley's avatar
Bob Halley committed
75 76 77
	/*
	 * Setup a logging context.
	 */
Bob Halley's avatar
Bob Halley committed
78 79 80 81 82 83 84
	result = isc_log_create(ns_g_mctx, &ns_g_lctx);
	if (result != ISC_R_SUCCESS)
		return (result);
	result = isc_log_registercategories(ns_g_lctx, ns_g_categories);
	if (result != ISC_R_SUCCESS)
		goto cleanup;
	isc_log_registermodules(ns_g_lctx, ns_g_modules);
Bob Halley's avatar
Bob Halley committed
85 86 87 88 89 90 91
	result = dns_log_init(ns_g_lctx);
	if (result != ISC_R_SUCCESS)
		goto cleanup;

	/*
	 * Create and install the default channel.
	 */
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
	if (ns_g_foreground) {
		destination.file.stream = stderr;
		destination.file.name = NULL;
		destination.file.versions = ISC_LOG_ROLLNEVER;
		destination.file.maximum_size = 0;
		flags = ISC_LOG_PRINTTIME;
		result = isc_log_createchannel(ns_g_lctx, "_default",
					       ISC_LOG_TOFILEDESC,
					       ISC_LOG_DYNAMIC,
					       &destination, flags);
	} else {
		destination.facility = LOG_DAEMON;
		flags = ISC_LOG_PRINTTIME;
		result = isc_log_createchannel(ns_g_lctx, "_default",
					       ISC_LOG_TOSYSLOG,
					       ISC_LOG_DYNAMIC,
					       &destination, flags);
	}
	
Bob Halley's avatar
Bob Halley committed
111 112 113 114 115
	if (result != ISC_R_SUCCESS)
		goto cleanup;
	result = isc_log_usechannel(ns_g_lctx, "_default", NULL, NULL);
	if (result != ISC_R_SUCCESS)
		goto cleanup;
Bob Halley's avatar
Bob Halley committed
116 117 118 119

	/*
	 * Set the initial debug level.
	 */
Bob Halley's avatar
Bob Halley committed
120 121 122 123 124 125 126 127 128 129 130 131 132 133
	isc_log_setdebuglevel(ns_g_lctx, ns_g_debuglevel);

	return (ISC_R_SUCCESS);

 cleanup:
	isc_log_destroy(&ns_g_lctx);

	return (result);
}

void
ns_log_shutdown(void) {
	isc_log_destroy(&ns_g_lctx);
}