log.c revision 7193a1762e428cfba06907e51fa9e4bce3b5569a
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[] = {
5fe5a0c02634eaadfcbc3528bf2c184557110a3bAndreas Gustafsson { "", 0 },
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley { "client", 0 },
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley { "network", 0 },
8327c62a49a2487d29a37acbed6b602e629fc0eeAndreas Gustafsson { "update", 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
7193a1762e428cfba06907e51fa9e4bce3b5569aAndreas Gustafssonns_log_init(isc_boolean_t safe) {
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley isc_result_t result;
edcd1247ad7e81bb8b430e610d9718f64c70f05dDavid Lawrence isc_logconfig_t *lcfg;
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley ns_g_categories = categories;
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley ns_g_modules = modules;
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley
8582a1e113c13886ccbd1b534d6c240315767be6Bob Halley /*
8582a1e113c13886ccbd1b534d6c240315767be6Bob Halley * Setup a logging context.
8582a1e113c13886ccbd1b534d6c240315767be6Bob Halley */
edcd1247ad7e81bb8b430e610d9718f64c70f05dDavid Lawrence result = isc_log_create(ns_g_mctx, &ns_g_lctx, &lcfg);
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley if (result != ISC_R_SUCCESS)
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley return (result);
edcd1247ad7e81bb8b430e610d9718f64c70f05dDavid Lawrence
edcd1247ad7e81bb8b430e610d9718f64c70f05dDavid Lawrence isc_log_registercategories(ns_g_lctx, ns_g_categories);
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley isc_log_registermodules(ns_g_lctx, ns_g_modules);
edcd1247ad7e81bb8b430e610d9718f64c70f05dDavid Lawrence dns_log_init(ns_g_lctx);
8582a1e113c13886ccbd1b534d6c240315767be6Bob Halley
7193a1762e428cfba06907e51fa9e4bce3b5569aAndreas Gustafsson if (safe)
7193a1762e428cfba06907e51fa9e4bce3b5569aAndreas Gustafsson result = ns_log_setsafechannels(lcfg);
7193a1762e428cfba06907e51fa9e4bce3b5569aAndreas Gustafsson else
7193a1762e428cfba06907e51fa9e4bce3b5569aAndreas Gustafsson result = ns_log_setdefaultchannels(lcfg);
a0f6cda5fd9f2fcc4154bb63628f849b639a40caAndreas Gustafsson if (result != ISC_R_SUCCESS)
a0f6cda5fd9f2fcc4154bb63628f849b639a40caAndreas Gustafsson goto cleanup;
7193a1762e428cfba06907e51fa9e4bce3b5569aAndreas Gustafsson
a0f6cda5fd9f2fcc4154bb63628f849b639a40caAndreas Gustafsson result = ns_log_setdefaultcategory(lcfg);
e02c696ea586f8dcc7c6145cc0f143f887960cd4Andreas Gustafsson if (result != ISC_R_SUCCESS)
e02c696ea586f8dcc7c6145cc0f143f887960cd4Andreas Gustafsson goto cleanup;
e02c696ea586f8dcc7c6145cc0f143f887960cd4Andreas Gustafsson
e02c696ea586f8dcc7c6145cc0f143f887960cd4Andreas Gustafsson return (ISC_R_SUCCESS);
e02c696ea586f8dcc7c6145cc0f143f887960cd4Andreas Gustafsson
e02c696ea586f8dcc7c6145cc0f143f887960cd4Andreas Gustafsson cleanup:
e02c696ea586f8dcc7c6145cc0f143f887960cd4Andreas Gustafsson isc_log_destroy(&ns_g_lctx);
e02c696ea586f8dcc7c6145cc0f143f887960cd4Andreas Gustafsson
e02c696ea586f8dcc7c6145cc0f143f887960cd4Andreas Gustafsson return (result);
e02c696ea586f8dcc7c6145cc0f143f887960cd4Andreas Gustafsson}
e02c696ea586f8dcc7c6145cc0f143f887960cd4Andreas Gustafsson
e02c696ea586f8dcc7c6145cc0f143f887960cd4Andreas Gustafssonisc_result_t
a0f6cda5fd9f2fcc4154bb63628f849b639a40caAndreas Gustafssonns_log_setdefaultchannels(isc_logconfig_t *lcfg) {
e02c696ea586f8dcc7c6145cc0f143f887960cd4Andreas Gustafsson isc_result_t result;
e02c696ea586f8dcc7c6145cc0f143f887960cd4Andreas Gustafsson isc_logdestination_t destination;
e02c696ea586f8dcc7c6145cc0f143f887960cd4Andreas Gustafsson
8582a1e113c13886ccbd1b534d6c240315767be6Bob Halley /*
11d435aa4cf77e035445978f7e3776a3589715fdAndreas Gustafsson * By default, the logging library makes "default_debug" log to
11d435aa4cf77e035445978f7e3776a3589715fdAndreas Gustafsson * stderr. In BIND, we want to override this and log to named.run
11d435aa4cf77e035445978f7e3776a3589715fdAndreas Gustafsson * instead, unless the the -g option was given.
8582a1e113c13886ccbd1b534d6c240315767be6Bob Halley */
11d435aa4cf77e035445978f7e3776a3589715fdAndreas Gustafsson if (! ns_g_logstderr) {
11d435aa4cf77e035445978f7e3776a3589715fdAndreas Gustafsson destination.file.stream = NULL;
11d435aa4cf77e035445978f7e3776a3589715fdAndreas Gustafsson destination.file.name = "named.run";
44fee668021c7ceef4ee1c848031d883a508b359James Brister destination.file.versions = ISC_LOG_ROLLNEVER;
44fee668021c7ceef4ee1c848031d883a508b359James Brister destination.file.maximum_size = 0;
11d435aa4cf77e035445978f7e3776a3589715fdAndreas Gustafsson result = isc_log_createchannel(lcfg, "default_debug",
11d435aa4cf77e035445978f7e3776a3589715fdAndreas Gustafsson ISC_LOG_TOFILE,
11d435aa4cf77e035445978f7e3776a3589715fdAndreas Gustafsson ISC_LOG_DYNAMIC,
11d435aa4cf77e035445978f7e3776a3589715fdAndreas Gustafsson &destination,
11d435aa4cf77e035445978f7e3776a3589715fdAndreas Gustafsson ISC_LOG_PRINTTIME|
11d435aa4cf77e035445978f7e3776a3589715fdAndreas Gustafsson ISC_LOG_DEBUGONLY);
11d435aa4cf77e035445978f7e3776a3589715fdAndreas Gustafsson if (result != ISC_R_SUCCESS)
11d435aa4cf77e035445978f7e3776a3589715fdAndreas Gustafsson goto cleanup;
44fee668021c7ceef4ee1c848031d883a508b359James Brister }
11d435aa4cf77e035445978f7e3776a3589715fdAndreas Gustafsson
a0f6cda5fd9f2fcc4154bb63628f849b639a40caAndreas Gustafsson /*
a0f6cda5fd9f2fcc4154bb63628f849b639a40caAndreas Gustafsson * Set the initial debug level.
a0f6cda5fd9f2fcc4154bb63628f849b639a40caAndreas Gustafsson */
a0f6cda5fd9f2fcc4154bb63628f849b639a40caAndreas Gustafsson isc_log_setdebuglevel(ns_g_lctx, ns_g_debuglevel);
a0f6cda5fd9f2fcc4154bb63628f849b639a40caAndreas Gustafsson
a0f6cda5fd9f2fcc4154bb63628f849b639a40caAndreas Gustafsson result = ISC_R_SUCCESS;
a0f6cda5fd9f2fcc4154bb63628f849b639a40caAndreas Gustafsson
a0f6cda5fd9f2fcc4154bb63628f849b639a40caAndreas Gustafsson cleanup:
a0f6cda5fd9f2fcc4154bb63628f849b639a40caAndreas Gustafsson return (result);
a0f6cda5fd9f2fcc4154bb63628f849b639a40caAndreas Gustafsson}
a0f6cda5fd9f2fcc4154bb63628f849b639a40caAndreas Gustafsson
7193a1762e428cfba06907e51fa9e4bce3b5569aAndreas Gustafssonisc_result_t
7193a1762e428cfba06907e51fa9e4bce3b5569aAndreas Gustafssonns_log_setsafechannels(isc_logconfig_t *lcfg) {
7193a1762e428cfba06907e51fa9e4bce3b5569aAndreas Gustafsson isc_result_t result;
7193a1762e428cfba06907e51fa9e4bce3b5569aAndreas Gustafsson
7193a1762e428cfba06907e51fa9e4bce3b5569aAndreas Gustafsson if (! ns_g_logstderr) {
7193a1762e428cfba06907e51fa9e4bce3b5569aAndreas Gustafsson result = isc_log_createchannel(lcfg, "default_debug",
7193a1762e428cfba06907e51fa9e4bce3b5569aAndreas Gustafsson ISC_LOG_TONULL,
7193a1762e428cfba06907e51fa9e4bce3b5569aAndreas Gustafsson ISC_LOG_DYNAMIC,
7193a1762e428cfba06907e51fa9e4bce3b5569aAndreas Gustafsson NULL, 0);
7193a1762e428cfba06907e51fa9e4bce3b5569aAndreas Gustafsson if (result != ISC_R_SUCCESS)
7193a1762e428cfba06907e51fa9e4bce3b5569aAndreas Gustafsson goto cleanup;
7193a1762e428cfba06907e51fa9e4bce3b5569aAndreas Gustafsson }
7193a1762e428cfba06907e51fa9e4bce3b5569aAndreas Gustafsson
7193a1762e428cfba06907e51fa9e4bce3b5569aAndreas Gustafsson /*
7193a1762e428cfba06907e51fa9e4bce3b5569aAndreas Gustafsson * Setting the debug level to zero should get the output
7193a1762e428cfba06907e51fa9e4bce3b5569aAndreas Gustafsson * discarded a bit faster.
7193a1762e428cfba06907e51fa9e4bce3b5569aAndreas Gustafsson */
7193a1762e428cfba06907e51fa9e4bce3b5569aAndreas Gustafsson isc_log_setdebuglevel(ns_g_lctx, 0);
7193a1762e428cfba06907e51fa9e4bce3b5569aAndreas Gustafsson
7193a1762e428cfba06907e51fa9e4bce3b5569aAndreas Gustafsson result = ISC_R_SUCCESS;
7193a1762e428cfba06907e51fa9e4bce3b5569aAndreas Gustafsson
7193a1762e428cfba06907e51fa9e4bce3b5569aAndreas Gustafsson cleanup:
7193a1762e428cfba06907e51fa9e4bce3b5569aAndreas Gustafsson return (result);
7193a1762e428cfba06907e51fa9e4bce3b5569aAndreas Gustafsson}
7193a1762e428cfba06907e51fa9e4bce3b5569aAndreas Gustafsson
a0f6cda5fd9f2fcc4154bb63628f849b639a40caAndreas Gustafssonisc_result_t
a0f6cda5fd9f2fcc4154bb63628f849b639a40caAndreas Gustafssonns_log_setdefaultcategory(isc_logconfig_t *lcfg) {
a0f6cda5fd9f2fcc4154bb63628f849b639a40caAndreas Gustafsson isc_result_t result;
a0f6cda5fd9f2fcc4154bb63628f849b639a40caAndreas Gustafsson
5542df09597c479be604da0ece8271cbc6fd9c4aDavid Lawrence result = isc_log_usechannel(lcfg, "default_syslog",
5542df09597c479be604da0ece8271cbc6fd9c4aDavid Lawrence ISC_LOGCATEGORY_DEFAULT, NULL);
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley if (result != ISC_R_SUCCESS)
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley goto cleanup;
11d435aa4cf77e035445978f7e3776a3589715fdAndreas Gustafsson
5542df09597c479be604da0ece8271cbc6fd9c4aDavid Lawrence result = isc_log_usechannel(lcfg, "default_debug",
5542df09597c479be604da0ece8271cbc6fd9c4aDavid Lawrence ISC_LOGCATEGORY_DEFAULT, NULL);
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley if (result != ISC_R_SUCCESS)
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley goto cleanup;
8582a1e113c13886ccbd1b534d6c240315767be6Bob Halley
a0f6cda5fd9f2fcc4154bb63628f849b639a40caAndreas Gustafsson result = ISC_R_SUCCESS;
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley
1687985cdfc3a4c330c5bdb02c131835f8756e3cBob Halley cleanup:
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}