log.c revision 8f7cae3d7b0c122c3b17e8409bbb80005433acd2
f2314fbd7911bacccf87d13562b38fafa1aac9eaMichael Graff/*
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Copyright (C) 1999, 2000 Internet Software Consortium.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence *
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Permission to use, copy, modify, and distribute this software for any
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * purpose with or without fee is hereby granted, provided that the above
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * copyright notice and this permission notice appear in all copies.
f2314fbd7911bacccf87d13562b38fafa1aac9eaMichael Graff *
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
53f0234c3e3a845245042affb1f20a189d8791b9Automatic Updater * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff */
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff/* $Id: log.c,v 1.23 2000/08/25 01:08:19 bwelling Exp $ */
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff#include <config.h>
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff#include <isc/result.h>
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff#include <named/log.h>
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff/*
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff * When adding a new category, be sure to add the appropriate
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff * #define to <named/log.h>.
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff */
c40906dfad6dd6e3a3e3c94b8c8847bc9bc064e5Mark Andrewsstatic isc_logcategory_t categories[] = {
c40906dfad6dd6e3a3e3c94b8c8847bc9bc064e5Mark Andrews { "", 0 },
c40906dfad6dd6e3a3e3c94b8c8847bc9bc064e5Mark Andrews { "client", 0 },
c40906dfad6dd6e3a3e3c94b8c8847bc9bc064e5Mark Andrews { "network", 0 },
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff { "update", 0 },
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff { NULL, 0 }
c1d7e0562f6a72ecc07ab5140cf2b88183adbd08Francis Dupont};
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff/*
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * When adding a new module, be sure to add the appropriate
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * #define to <dns/log.h>.
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt */
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Huntstatic isc_logmodule_t modules[] = {
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt { "main", 0 },
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt { "client", 0 },
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff { "server", 0 },
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff { "query", 0 },
c1d7e0562f6a72ecc07ab5140cf2b88183adbd08Francis Dupont { "interfacemgr", 0 },
22bed621ef87bc8b6c1fea599b02c4b38dd6bf48Mark Andrews { "update", 0 },
76af83c9adb772f7b045c62cf8b411165bfaa5efMark Andrews { "xfer-in", 0 },
76af83c9adb772f7b045c62cf8b411165bfaa5efMark Andrews { "xfer-out", 0 },
76af83c9adb772f7b045c62cf8b411165bfaa5efMark Andrews { "notify", 0 },
76af83c9adb772f7b045c62cf8b411165bfaa5efMark Andrews { "omapi", 0 },
c1d7e0562f6a72ecc07ab5140cf2b88183adbd08Francis Dupont { "lwresd", 0 },
c1d7e0562f6a72ecc07ab5140cf2b88183adbd08Francis Dupont { NULL, 0 }
76af83c9adb772f7b045c62cf8b411165bfaa5efMark Andrews};
76af83c9adb772f7b045c62cf8b411165bfaa5efMark Andrews
76af83c9adb772f7b045c62cf8b411165bfaa5efMark Andrewsisc_result_t
c1d7e0562f6a72ecc07ab5140cf2b88183adbd08Francis Dupontns_log_init(isc_boolean_t safe) {
c1d7e0562f6a72ecc07ab5140cf2b88183adbd08Francis Dupont isc_result_t result;
c1d7e0562f6a72ecc07ab5140cf2b88183adbd08Francis Dupont isc_logconfig_t *lcfg;
c1d7e0562f6a72ecc07ab5140cf2b88183adbd08Francis Dupont
76af83c9adb772f7b045c62cf8b411165bfaa5efMark Andrews ns_g_categories = categories;
76af83c9adb772f7b045c62cf8b411165bfaa5efMark Andrews ns_g_modules = modules;
c1d7e0562f6a72ecc07ab5140cf2b88183adbd08Francis Dupont
c1d7e0562f6a72ecc07ab5140cf2b88183adbd08Francis Dupont /*
c1d7e0562f6a72ecc07ab5140cf2b88183adbd08Francis Dupont * Setup a logging context.
c1d7e0562f6a72ecc07ab5140cf2b88183adbd08Francis Dupont */
8e73941f33fad57111142a62d99717abc001912eMark Andrews result = isc_log_create(ns_g_mctx, &ns_g_lctx, &lcfg);
8e73941f33fad57111142a62d99717abc001912eMark Andrews if (result != ISC_R_SUCCESS)
76af83c9adb772f7b045c62cf8b411165bfaa5efMark Andrews return (result);
fc63119c8b7aa8827fad9e3e45e50c69bc2630e8Francis Dupont
fc63119c8b7aa8827fad9e3e45e50c69bc2630e8Francis Dupont isc_log_registercategories(ns_g_lctx, ns_g_categories);
c1d7e0562f6a72ecc07ab5140cf2b88183adbd08Francis Dupont isc_log_registermodules(ns_g_lctx, ns_g_modules);
c1d7e0562f6a72ecc07ab5140cf2b88183adbd08Francis Dupont isc_log_setcontext(ns_g_lctx);
c1d7e0562f6a72ecc07ab5140cf2b88183adbd08Francis Dupont dns_log_init(ns_g_lctx);
c1d7e0562f6a72ecc07ab5140cf2b88183adbd08Francis Dupont dns_log_setcontext(ns_g_lctx);
76af83c9adb772f7b045c62cf8b411165bfaa5efMark Andrews
76af83c9adb772f7b045c62cf8b411165bfaa5efMark Andrews if (safe)
76af83c9adb772f7b045c62cf8b411165bfaa5efMark Andrews result = ns_log_setsafechannels(lcfg);
c1d7e0562f6a72ecc07ab5140cf2b88183adbd08Francis Dupont else
c1d7e0562f6a72ecc07ab5140cf2b88183adbd08Francis Dupont result = ns_log_setdefaultchannels(lcfg);
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt if (result != ISC_R_SUCCESS)
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt goto cleanup;
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt result = ns_log_setdefaultcategory(lcfg);
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt if (result != ISC_R_SUCCESS)
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt goto cleanup;
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt
acbb301e648b82fcc38b876a44403cf0fe539cc9Evan Hunt return (ISC_R_SUCCESS);
acbb301e648b82fcc38b876a44403cf0fe539cc9Evan Hunt
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt cleanup:
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt isc_log_destroy(&ns_g_lctx);
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt return (result);
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt}
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Huntisc_result_t
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Huntns_log_setdefaultchannels(isc_logconfig_t *lcfg) {
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt isc_result_t result;
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt isc_logdestination_t destination;
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt /*
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * By default, the logging library makes "default_debug" log to
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * stderr. In BIND, we want to override this and log to named.run
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * instead, unless the the -g option was given.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt */
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt if (! ns_g_logstderr) {
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt destination.file.stream = NULL;
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt destination.file.name = "named.run";
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt destination.file.versions = ISC_LOG_ROLLNEVER;
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt destination.file.maximum_size = 0;
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt result = isc_log_createchannel(lcfg, "default_debug",
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt ISC_LOG_TOFILE,
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt ISC_LOG_DYNAMIC,
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt &destination,
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt ISC_LOG_PRINTTIME|
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt ISC_LOG_DEBUGONLY);
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt if (result != ISC_R_SUCCESS)
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt goto cleanup;
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt }
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt /*
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * Set the initial debug level.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt */
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt isc_log_setdebuglevel(ns_g_lctx, ns_g_debuglevel);
c1d7e0562f6a72ecc07ab5140cf2b88183adbd08Francis Dupont
c1d7e0562f6a72ecc07ab5140cf2b88183adbd08Francis Dupont result = ISC_R_SUCCESS;
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff cleanup:
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff return (result);
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff}
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graffisc_result_t
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graffns_log_setsafechannels(isc_logconfig_t *lcfg) {
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff isc_result_t result;
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff if (! ns_g_logstderr) {
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff result = isc_log_createchannel(lcfg, "default_debug",
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff ISC_LOG_TONULL,
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein ISC_LOG_DYNAMIC,
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff NULL, 0);
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff if (result != ISC_R_SUCCESS)
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff goto cleanup;
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff }
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff /*
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff * Setting the debug level to zero should get the output
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff * discarded a bit faster.
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff */
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff isc_log_setdebuglevel(ns_g_lctx, 0);
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff result = ISC_R_SUCCESS;
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff cleanup:
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff return (result);
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff}
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graffisc_result_t
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graffns_log_setdefaultcategory(isc_logconfig_t *lcfg) {
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein isc_result_t result;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff result = isc_log_usechannel(lcfg, "default_syslog",
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff ISC_LOGCATEGORY_DEFAULT, NULL);
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff if (result != ISC_R_SUCCESS)
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff goto cleanup;
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff result = isc_log_usechannel(lcfg, "default_debug",
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein ISC_LOGCATEGORY_DEFAULT, NULL);
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff if (result != ISC_R_SUCCESS)
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein goto cleanup;
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff result = ISC_R_SUCCESS;
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein cleanup:
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff return (result);
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff}
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graffvoid
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graffns_log_shutdown(void) {
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff isc_log_destroy(&ns_g_lctx);
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff}
bb2d54f1b3654857b8cb0209612ed847afbd9d3cMichael Graff