log.c revision 7d98a1783f222964bcde7d56dab77b822706204d
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley/*
7d98a1783f222964bcde7d56dab77b822706204dBob Halley * Copyright (C) 1999, 2000 Internet Software Consortium.
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley *
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley * Permission to use, copy, modify, and distribute this software for any
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley * purpose with or without fee is hereby granted, provided that the above
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley * copyright notice and this permission notice appear in all copies.
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley *
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley * SOFTWARE.
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley */
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley#include <config.h>
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley#include <isc/assertions.h>
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley#include <isc/log.h>
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley#include <isc/result.h>
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley#include <dns/log.h>
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley#include <named/globals.h>
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley#include <named/log.h>
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley/*
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley * When adding a new category, be sure to add the appropriate
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley * #define to <named/log.h>.
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley */
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halleystatic isc_logcategory_t categories[] = {
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley { "general", 0 },
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley { "client", 0 },
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley { "network", 0 },
8327c62a49a2487d29a37acbed6b602e629fc0eeAndreas Gustafsson { "update", 0 },
8327c62a49a2487d29a37acbed6b602e629fc0eeAndreas Gustafsson { "xfer-in", 0 },
8327c62a49a2487d29a37acbed6b602e629fc0eeAndreas Gustafsson { "xfer-out", 0 },
608f870f4821972313eadc5388a42fa55b6279d1Mark Andrews { "notify", 0 },
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley { NULL, 0 }
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley};
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley/*
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley * When adding a new module, be sure to add the appropriate
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley * #define to <dns/log.h>.
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley */
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halleystatic isc_logmodule_t modules[] = {
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley { "main", 0 },
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley { "client", 0 },
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley { "server", 0 },
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley { "query", 0 },
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley { "interfacemgr", 0 },
8327c62a49a2487d29a37acbed6b602e629fc0eeAndreas Gustafsson { "update", 0 },
8327c62a49a2487d29a37acbed6b602e629fc0eeAndreas Gustafsson { "xfer-in", 0 },
8327c62a49a2487d29a37acbed6b602e629fc0eeAndreas Gustafsson { "xfer-out", 0 },
608f870f4821972313eadc5388a42fa55b6279d1Mark Andrews { "notify", 0 },
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley { NULL, 0 }
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley};
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halleyisc_result_t
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halleyns_log_init(void) {
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley isc_result_t result;
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley isc_logdestination_t destination;
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley unsigned int flags;
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley ns_g_categories = categories;
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley ns_g_modules = modules;
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley /*
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley * XXXRTH This is not necessarily the final default logging
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley * setup.
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley */
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley
8582a1e113c13886ccbd1b534d6c240315767be6Bob Halley /*
8582a1e113c13886ccbd1b534d6c240315767be6Bob Halley * Setup a logging context.
8582a1e113c13886ccbd1b534d6c240315767be6Bob Halley */
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley result = isc_log_create(ns_g_mctx, &ns_g_lctx);
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley if (result != ISC_R_SUCCESS)
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley return (result);
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley result = isc_log_registercategories(ns_g_lctx, ns_g_categories);
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley if (result != ISC_R_SUCCESS)
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley goto cleanup;
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley isc_log_registermodules(ns_g_lctx, ns_g_modules);
8582a1e113c13886ccbd1b534d6c240315767be6Bob Halley result = dns_log_init(ns_g_lctx);
8582a1e113c13886ccbd1b534d6c240315767be6Bob Halley if (result != ISC_R_SUCCESS)
8582a1e113c13886ccbd1b534d6c240315767be6Bob Halley goto cleanup;
8582a1e113c13886ccbd1b534d6c240315767be6Bob Halley
8582a1e113c13886ccbd1b534d6c240315767be6Bob Halley /*
8582a1e113c13886ccbd1b534d6c240315767be6Bob Halley * Create and install the default channel.
8582a1e113c13886ccbd1b534d6c240315767be6Bob Halley */
44fee668021c7ceef4ee1c848031d883a508b359James Brister if (ns_g_foreground) {
44fee668021c7ceef4ee1c848031d883a508b359James Brister destination.file.stream = stderr;
44fee668021c7ceef4ee1c848031d883a508b359James Brister destination.file.name = NULL;
44fee668021c7ceef4ee1c848031d883a508b359James Brister destination.file.versions = ISC_LOG_ROLLNEVER;
44fee668021c7ceef4ee1c848031d883a508b359James Brister destination.file.maximum_size = 0;
44fee668021c7ceef4ee1c848031d883a508b359James Brister flags = ISC_LOG_PRINTTIME;
44fee668021c7ceef4ee1c848031d883a508b359James Brister result = isc_log_createchannel(ns_g_lctx, "_default",
44fee668021c7ceef4ee1c848031d883a508b359James Brister ISC_LOG_TOFILEDESC,
44fee668021c7ceef4ee1c848031d883a508b359James Brister ISC_LOG_DYNAMIC,
44fee668021c7ceef4ee1c848031d883a508b359James Brister &destination, flags);
44fee668021c7ceef4ee1c848031d883a508b359James Brister } else {
44fee668021c7ceef4ee1c848031d883a508b359James Brister destination.facility = LOG_DAEMON;
44fee668021c7ceef4ee1c848031d883a508b359James Brister flags = ISC_LOG_PRINTTIME;
44fee668021c7ceef4ee1c848031d883a508b359James Brister result = isc_log_createchannel(ns_g_lctx, "_default",
44fee668021c7ceef4ee1c848031d883a508b359James Brister ISC_LOG_TOSYSLOG,
44fee668021c7ceef4ee1c848031d883a508b359James Brister ISC_LOG_DYNAMIC,
44fee668021c7ceef4ee1c848031d883a508b359James Brister &destination, flags);
44fee668021c7ceef4ee1c848031d883a508b359James Brister }
44fee668021c7ceef4ee1c848031d883a508b359James Brister
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley if (result != ISC_R_SUCCESS)
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley goto cleanup;
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley result = isc_log_usechannel(ns_g_lctx, "_default", NULL, NULL);
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley if (result != ISC_R_SUCCESS)
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley goto cleanup;
8582a1e113c13886ccbd1b534d6c240315767be6Bob Halley
8582a1e113c13886ccbd1b534d6c240315767be6Bob Halley /*
8582a1e113c13886ccbd1b534d6c240315767be6Bob Halley * Set the initial debug level.
8582a1e113c13886ccbd1b534d6c240315767be6Bob Halley */
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley isc_log_setdebuglevel(ns_g_lctx, ns_g_debuglevel);
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley return (ISC_R_SUCCESS);
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley cleanup:
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley isc_log_destroy(&ns_g_lctx);
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley return (result);
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley}
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halleyvoid
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halleyns_log_shutdown(void) {
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley isc_log_destroy(&ns_g_lctx);
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley}