#include <config.h>
#include <isc/result.h>
#include <isccfg/log.h>
#include <named/log.h>
static isc_logcategory_t categories[] = {
{ "", 0 },
{ "client", 0 },
{ "network", 0 },
{ "update", 0 },
{ "queries", 0 },
{ "unmatched", 0 },
{ NULL, 0 }
};
static isc_logmodule_t modules[] = {
{ "main", 0 },
{ "client", 0 },
{ "server", 0 },
{ "query", 0 },
{ "interfacemgr", 0 },
{ "update", 0 },
{ "xfer-in", 0 },
{ "xfer-out", 0 },
{ "notify", 0 },
{ "control", 0 },
{ "lwresd", 0 },
{ NULL, 0 }
};
isc_result_t
ns_log_init(isc_boolean_t safe) {
isc_result_t result;
isc_logconfig_t *lcfg = NULL;
ns_g_categories = categories;
ns_g_modules = modules;
result = isc_log_create(ns_g_mctx, &ns_g_lctx, &lcfg);
if (result != ISC_R_SUCCESS)
return (result);
isc_log_registercategories(ns_g_lctx, ns_g_categories);
isc_log_registermodules(ns_g_lctx, ns_g_modules);
isc_log_setcontext(ns_g_lctx);
dns_log_init(ns_g_lctx);
dns_log_setcontext(ns_g_lctx);
cfg_log_init(ns_g_lctx);
if (safe)
result = ns_log_setsafechannels(lcfg);
else
result = ns_log_setdefaultchannels(lcfg);
if (result != ISC_R_SUCCESS)
goto cleanup;
result = ns_log_setdefaultcategory(lcfg);
if (result != ISC_R_SUCCESS)
goto cleanup;
return (ISC_R_SUCCESS);
cleanup:
isc_log_destroy(&ns_g_lctx);
isc_log_setcontext(NULL);
dns_log_setcontext(NULL);
return (result);
}
isc_result_t
ns_log_setdefaultchannels(isc_logconfig_t *lcfg) {
isc_result_t result;
isc_logdestination_t destination;
if (! ns_g_logstderr) {
destination.file.stream = NULL;
destination.file.name = "named.run";
destination.file.versions = ISC_LOG_ROLLNEVER;
destination.file.maximum_size = 0;
result = isc_log_createchannel(lcfg, "default_debug",
ISC_LOG_TOFILE,
ISC_LOG_DYNAMIC,
&destination,
ISC_LOG_PRINTTIME|
ISC_LOG_DEBUGONLY);
if (result != ISC_R_SUCCESS)
goto cleanup;
}
isc_log_setdebuglevel(ns_g_lctx, ns_g_debuglevel);
result = ISC_R_SUCCESS;
cleanup:
return (result);
}
isc_result_t
ns_log_setsafechannels(isc_logconfig_t *lcfg) {
isc_result_t result;
if (! ns_g_logstderr) {
result = isc_log_createchannel(lcfg, "default_debug",
ISC_LOG_TONULL,
ISC_LOG_DYNAMIC,
NULL, 0);
if (result != ISC_R_SUCCESS)
goto cleanup;
isc_log_setdebuglevel(ns_g_lctx, 0);
} else {
isc_log_setdebuglevel(ns_g_lctx, ns_g_debuglevel);
}
result = ISC_R_SUCCESS;
cleanup:
return (result);
}
isc_result_t
ns_log_setdefaultcategory(isc_logconfig_t *lcfg) {
isc_result_t result;
if (! ns_g_logstderr) {
result = isc_log_usechannel(lcfg, "default_syslog",
ISC_LOGCATEGORY_DEFAULT, NULL);
if (result != ISC_R_SUCCESS)
goto cleanup;
}
result = isc_log_usechannel(lcfg, "default_debug",
ISC_LOGCATEGORY_DEFAULT, NULL);
if (result != ISC_R_SUCCESS)
goto cleanup;
result = ISC_R_SUCCESS;
cleanup:
return (result);
}
isc_result_t
ns_log_setunmatchedcategory(isc_logconfig_t *lcfg) {
isc_result_t result;
result = isc_log_usechannel(lcfg, "null",
NS_LOGCATEGORY_UNMATCHED, NULL);
return (result);
}
void
ns_log_shutdown(void) {
isc_log_destroy(&ns_g_lctx);
isc_log_setcontext(NULL);
dns_log_setcontext(NULL);
}