コード例 #1
0
ファイル: logconf.c プロジェクト: Distrotech/bind
isc_result_t
ns_log_configure(isc_logconfig_t *logconf, const cfg_obj_t *logstmt) {
	isc_result_t result;
	const cfg_obj_t *channels = NULL;
	const cfg_obj_t *categories = NULL;
	const cfg_listelt_t *element;
	isc_boolean_t default_set = ISC_FALSE;
	isc_boolean_t unmatched_set = ISC_FALSE;
	const cfg_obj_t *catname;

	CHECK(ns_log_setdefaultchannels(logconf));

	(void)cfg_map_get(logstmt, "channel", &channels);
	for (element = cfg_list_first(channels);
	     element != NULL;
	     element = cfg_list_next(element))
	{
		const cfg_obj_t *channel = cfg_listelt_value(element);
		CHECK(channel_fromconf(channel, logconf));
	}

	(void)cfg_map_get(logstmt, "category", &categories);
	for (element = cfg_list_first(categories);
	     element != NULL;
	     element = cfg_list_next(element))
	{
		const cfg_obj_t *category = cfg_listelt_value(element);
		CHECK(category_fromconf(category, logconf));
		if (!default_set) {
			catname = cfg_tuple_get(category, "name");
			if (strcmp(cfg_obj_asstring(catname), "default") == 0)
				default_set = ISC_TRUE;
		}
		if (!unmatched_set) {
			catname = cfg_tuple_get(category, "name");
			if (strcmp(cfg_obj_asstring(catname), "unmatched") == 0)
				unmatched_set = ISC_TRUE;
		}
	}

	if (!default_set)
		CHECK(ns_log_setdefaultcategory(logconf));

	if (!unmatched_set)
		CHECK(ns_log_setunmatchedcategory(logconf));

	return (ISC_R_SUCCESS);

 cleanup:
	if (logconf != NULL)
		isc_logconfig_destroy(&logconf);
	return (result);
}
コード例 #2
0
ファイル: log.c プロジェクト: 274914765/C
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;

    /*
     * Setup a logging context.
     */
    result = isc_log_create (ns_g_mctx, &ns_g_lctx, &lcfg);
    if (result != ISC_R_SUCCESS)
        return (result);

    /*
     * named-checktool.c:setup_logging() needs to be kept in sync.
     */
    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);
}