void n_log_set_target (NLogTarget target) { if (target == _log_target) return; _log_target = target; if (target == N_LOG_TARGET_SYSLOG) { openlog ("ngfd", 0, LOG_DAEMON); N_INFO (LOG_CAT "logging enabled to syslog"); } else { N_INFO (LOG_CAT "logging enabled to stdout."); closelog(); } }
int n_core_initialize (NCore *core) { g_assert (core != NULL); g_assert (core->conf_path != NULL); g_assert (core->plugin_path != NULL); NSinkInterface **sink = NULL; NInputInterface **input = NULL; NPlugin *plugin = NULL; GList *p = NULL; /* setup hooks */ n_hook_init (&core->hooks[N_CORE_HOOK_INIT_DONE]); n_hook_init (&core->hooks[N_CORE_HOOK_TRANSFORM_PROPERTIES]); n_hook_init (&core->hooks[N_CORE_HOOK_FILTER_SINKS]); /* load the default configuration. */ if (!n_core_parse_configuration (core)) goto failed_init; /* check for required plugins. */ if (!core->required_plugins && !core->optional_plugins) { N_ERROR (LOG_CAT "no plugins to load defined in configuration"); goto failed_init; } /* load events from the given event path. */ if (!n_core_parse_events (core)) goto failed_init; /* load all plugins */ /* first mandatory plugins */ for (p = g_list_first (core->required_plugins); p; p = g_list_next (p)) { if (!(plugin = n_core_load_plugin (core, (const char*) p->data))) goto failed_init; core->plugins = g_list_append (core->plugins, plugin); } /* then optional plugins */ for (p = g_list_first (core->optional_plugins); p; p = g_list_next (p)) { if ((plugin = n_core_load_plugin (core, (const char*) p->data))) core->plugins = g_list_append (core->plugins, plugin); if (!plugin) N_INFO (LOG_CAT "optional plugin %s not loaded.", p->data); } /* setup the sink priorities based on the sink-order */ n_core_set_sink_priorities (core->sinks, core->sink_order); /* initialize all sinks. if no sinks, we're done. */ if (!core->sinks) { N_ERROR (LOG_CAT "no plugin has registered sink interface"); goto failed_init; } for (sink = core->sinks; *sink; ++sink) { if ((*sink)->funcs.initialize && !(*sink)->funcs.initialize (*sink)) { N_ERROR (LOG_CAT "sink '%s' failed to initialize", (*sink)->name); goto failed_init; } } /* initialize all inputs. */ if (!core->inputs) { N_ERROR (LOG_CAT "no plugin has registered input interface"); goto failed_init; } for (input = core->inputs; *input; ++input) { if ((*input)->funcs.initialize && !(*input)->funcs.initialize (*input)) { N_ERROR (LOG_CAT "input '%s' failed to initialize", (*input)->name); goto failed_init; } } /* fire the init done hook. */ n_core_fire_hook (core, N_CORE_HOOK_INIT_DONE, NULL); return TRUE; failed_init: return FALSE; }