Reload logger configuration on SIGHUP
authorTobias Brunner <tobias@strongswan.org>
Thu, 4 Oct 2012 16:12:20 +0000 (18:12 +0200)
committerTobias Brunner <tobias@strongswan.org>
Thu, 18 Oct 2012 12:42:10 +0000 (14:42 +0200)
Besides changing the configuration this allows to easily rotate log files.

Also moved logger initialization back to daemon_t.

src/charon-nm/charon-nm.c
src/charon/charon.c
src/frontends/android/jni/libandroidbridge/charonservice.c
src/libcharon/daemon.c
src/libcharon/daemon.h
src/libcharon/plugins/stroke/stroke_socket.c

index 4857c99..61f2937 100644 (file)
@@ -117,28 +117,6 @@ static void segv_handler(int signal)
 }
 
 /**
- * Initialize logging to syslog
- */
-static void initialize_logger()
-{
-       sys_logger_t *sys_logger;
-       debug_t group;
-       level_t def;
-
-       sys_logger = sys_logger_create(LOG_DAEMON);
-       def = lib->settings->get_int(lib->settings,
-                                                                "charon-nm.syslog.default", 1);
-       for (group = 0; group < DBG_MAX; group++)
-       {
-               sys_logger->set_level(sys_logger, group,
-                       lib->settings->get_int(lib->settings, "charon-nm.syslog.%N", def,
-                                                                  debug_lower_names, group));
-       }
-       charon->sys_loggers->insert_last(charon->sys_loggers, sys_logger);
-       charon->bus->add_logger(charon->bus, &sys_logger->logger);
-}
-
-/**
  * Lookup UID and GID
  */
 static bool lookup_uid_gid()
@@ -204,7 +182,11 @@ int main(int argc, char *argv[])
                goto deinit;
        }
 
-       initialize_logger();
+       /* make sure we log to the DAEMON facility by default */
+       lib->settings->set_int(lib->settings, "charon-nm.syslog.daemon.default",
+               lib->settings->get_int(lib->settings,
+                                                          "charon-nm.syslog.daemon.default", 1));
+       charon->load_loggers(charon, NULL, FALSE);
 
        /* use random ports to avoid conflicts with regular charon */
        lib->settings->set_int(lib->settings, "charon-nm.port", 0);
index ba3e8fb..c301874 100644 (file)
@@ -24,8 +24,6 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <sys/utsname.h>
-#include <syslog.h>
-#include <errno.h>
 #include <unistd.h>
 #include <getopt.h>
 
 #include <private/android_filesystem_config.h> /* for AID_VPN */
 #endif
 
-#ifndef LOG_AUTHPRIV /* not defined on OpenSolaris */
-#define LOG_AUTHPRIV LOG_AUTH
-#endif
-
 /**
  * PID file, in which charon stores its process id
  */
 static FILE *pidfile = NULL;
 
 /**
+ * Log levels as defined via command line arguments
+ */
+static level_t levels[DBG_MAX];
+
+/**
+ * Whether to only use syslog when logging
+ */
+static bool use_syslog = FALSE;
+
+/**
  * hook in library for debugging messages
  */
 extern void (*dbg) (debug_t group, level_t level, char *fmt, ...);
@@ -109,6 +113,7 @@ static void run()
                                         "configuration");
                                if (lib->settings->load_files(lib->settings, NULL, FALSE))
                                {
+                                       charon->load_loggers(charon, levels, !use_syslog);
                                        lib->plugins->reload(lib->plugins, NULL);
                                }
                                else
@@ -239,123 +244,6 @@ static void unlink_pidfile()
 }
 
 /**
- * Initialize logging
- */
-static void initialize_loggers(bool use_stderr, level_t levels[])
-{
-       sys_logger_t *sys_logger;
-       file_logger_t *file_logger;
-       enumerator_t *enumerator;
-       char *identifier, *facility, *filename;
-       int loggers_defined = 0;
-       debug_t group;
-       level_t  def;
-
-       /* setup sysloggers */
-       identifier = lib->settings->get_str(lib->settings,
-                                                                               "charon.syslog.identifier", NULL);
-       if (identifier)
-       {       /* set identifier, which is prepended to each log line */
-               openlog(identifier, 0, 0);
-       }
-       enumerator = lib->settings->create_section_enumerator(lib->settings,
-                                                                                                                 "charon.syslog");
-       while (enumerator->enumerate(enumerator, &facility))
-       {
-               loggers_defined++;
-
-               if (streq(facility, "daemon"))
-               {
-                       sys_logger = sys_logger_create(LOG_DAEMON);
-               }
-               else if (streq(facility, "auth"))
-               {
-                       sys_logger = sys_logger_create(LOG_AUTHPRIV);
-               }
-               else
-               {
-                       continue;
-               }
-               sys_logger->set_options(sys_logger,
-                                               lib->settings->get_bool(lib->settings,
-                                                               "charon.syslog.%s.ike_name", FALSE, facility));
-
-               def = lib->settings->get_int(lib->settings,
-                                                                        "charon.syslog.%s.default", 1, facility);
-               for (group = 0; group < DBG_MAX; group++)
-               {
-                       sys_logger->set_level(sys_logger, group,
-                               lib->settings->get_int(lib->settings,
-                                                                          "charon.syslog.%s.%N", def,
-                                                                          facility, debug_lower_names, group));
-               }
-               charon->sys_loggers->insert_last(charon->sys_loggers, sys_logger);
-               charon->bus->add_logger(charon->bus, &sys_logger->logger);
-       }
-       enumerator->destroy(enumerator);
-
-       /* and file loggers */
-       enumerator = lib->settings->create_section_enumerator(lib->settings,
-                                                                                                                 "charon.filelog");
-       while (enumerator->enumerate(enumerator, &filename))
-       {
-               loggers_defined++;
-               file_logger = file_logger_create(filename);
-               file_logger->set_options(file_logger,
-                                               lib->settings->get_str(lib->settings,
-                                                       "charon.filelog.%s.time_format", NULL, filename),
-                                               lib->settings->get_bool(lib->settings,
-                                                       "charon.filelog.%s.ike_name", FALSE, filename));
-               file_logger->open(file_logger,
-                                               lib->settings->get_bool(lib->settings,
-                                                       "charon.filelog.%s.flush_line", FALSE, filename),
-                                               lib->settings->get_bool(lib->settings,
-                                                       "charon.filelog.%s.append", TRUE, filename));
-               def = lib->settings->get_int(lib->settings,
-                                                                        "charon.filelog.%s.default", 1, filename);
-               for (group = 0; group < DBG_MAX; group++)
-               {
-                       file_logger->set_level(file_logger, group,
-                               lib->settings->get_int(lib->settings,
-                                                                          "charon.filelog.%s.%N", def,
-                                                                          filename, debug_lower_names, group));
-               }
-               charon->file_loggers->insert_last(charon->file_loggers, file_logger);
-               charon->bus->add_logger(charon->bus, &file_logger->logger);
-
-       }
-       enumerator->destroy(enumerator);
-
-       /* set up legacy style default loggers provided via command-line */
-       if (!loggers_defined)
-       {
-               /* set up default stdout file_logger */
-               file_logger = file_logger_create("stdout");
-               file_logger->open(file_logger, FALSE, FALSE);
-               charon->file_loggers->insert_last(charon->file_loggers, file_logger);
-               /* set up default daemon sys_logger */
-               sys_logger = sys_logger_create(LOG_DAEMON);
-               charon->sys_loggers->insert_last(charon->sys_loggers, sys_logger);
-               for (group = 0; group < DBG_MAX; group++)
-               {
-                       sys_logger->set_level(sys_logger, group, levels[group]);
-                       if (use_stderr)
-                       {
-                               file_logger->set_level(file_logger, group, levels[group]);
-                       }
-               }
-               charon->bus->add_logger(charon->bus, &file_logger->logger);
-               charon->bus->add_logger(charon->bus, &sys_logger->logger);
-
-               /* set up default auth sys_logger */
-               sys_logger = sys_logger_create(LOG_AUTHPRIV);
-               sys_logger->set_level(sys_logger, DBG_ANY, LEVEL_AUDIT);
-               charon->sys_loggers->insert_last(charon->sys_loggers, sys_logger);
-               charon->bus->add_logger(charon->bus, &sys_logger->logger);
-       }
-}
-
-/**
  * print command line usage and exit
  */
 static void usage(const char *msg)
@@ -382,8 +270,6 @@ static void usage(const char *msg)
 int main(int argc, char *argv[])
 {
        struct sigaction action;
-       bool use_syslog = FALSE;
-       level_t levels[DBG_MAX];
        int group, status = SS_RC_INITIALIZATION_FAILED;
        struct utsname utsname;
 
@@ -487,7 +373,7 @@ int main(int argc, char *argv[])
                goto deinit;
        }
 
-       initialize_loggers(!use_syslog, levels);
+       charon->load_loggers(charon, levels, !use_syslog);
 
        if (uname(&utsname) != 0)
        {
index 1756eda..9204539 100644 (file)
@@ -129,25 +129,6 @@ static void dbg_android(debug_t group, level_t level, char *fmt, ...)
        }
 }
 
-/**
- * Initialize file logger
- */
-static void initialize_logger(char *logfile)
-{
-       file_logger_t *file_logger;
-       debug_t group;
-
-       file_logger = file_logger_create(logfile);
-       file_logger->set_options(file_logger, "%b %e %T", FALSE);
-       file_logger->open(file_logger, TRUE, FALSE);
-       for (group = 0; group < DBG_MAX; group++)
-       {
-               file_logger->set_level(file_logger, group, ANDROID_DEBUG_LEVEL);
-       }
-       charon->file_loggers->insert_last(charon->file_loggers, file_logger);
-       charon->bus->add_logger(charon->bus, &file_logger->logger);
-}
-
 METHOD(charonservice_t, update_status, bool,
        private_charonservice_t *this, android_vpn_state_t code)
 {
@@ -398,7 +379,8 @@ static bool charonservice_register(void *plugin, plugin_feature_t *feature,
 /**
  * Initialize the charonservice object
  */
-static void charonservice_init(JNIEnv *env, jobject service, jobject builder)
+static void charonservice_init(JNIEnv *env, jobject service, jobject builder,
+                                                          char *logfile)
 {
        private_charonservice_t *this;
        static plugin_feature_t features[] = {
@@ -435,6 +417,16 @@ static void charonservice_init(JNIEnv *env, jobject service, jobject builder)
 
        lib->settings->set_int(lib->settings,
                                        "charon.plugins.android_log.loglevel", ANDROID_DEBUG_LEVEL);
+       /* setup file logger */
+       lib->settings->set_str(lib->settings,
+                                       "charon.filelog.%s.time_format", "%b %e %T", logfile);
+       lib->settings->set_bool(lib->settings,
+                                       "charon.filelog.%s.append", FALSE, logfile);
+       lib->settings->set_bool(lib->settings,
+                                       "charon.filelog.%s.flush_line", TRUE, logfile);
+       lib->settings->set_int(lib->settings,
+                                       "charon.filelog.%s.default", ANDROID_DEBUG_LEVEL, logfile);
+
        lib->settings->set_int(lib->settings,
                                        "charon.retransmit_tries", ANDROID_RETRASNMIT_TRIES);
        lib->settings->set_double(lib->settings,
@@ -526,10 +518,10 @@ JNI_METHOD(CharonVpnService, initializeCharon, void,
        }
 
        logfile = androidjni_convert_jstring(env, jlogfile);
-       initialize_logger(logfile);
+       charonservice_init(env, this, builder, logfile);
        free(logfile);
 
-       charonservice_init(env, this, builder);
+       charon->load_loggers(charon, NULL, FALSE);
 
        if (uname(&utsname) != 0)
        {
index 9ae56a9..9ab857f 100644 (file)
 #include <stdio.h>
 #include <sys/types.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <time.h>
 
 #include "daemon.h"
 
 #include <library.h>
-#include <plugins/plugin_feature.h>
+#include <bus/listeners/sys_logger.h>
+#include <bus/listeners/file_logger.h>
 #include <config/proposal.h>
+#include <plugins/plugin_feature.h>
 #include <kernel/kernel_handler.h>
 #include <processing/jobs/start_action_job.h>
+#include <threading/mutex.h>
 
 #ifndef CAP_NET_ADMIN
 #define CAP_NET_ADMIN 12
 #endif
 
+#ifndef LOG_AUTHPRIV /* not defined on OpenSolaris */
+#define LOG_AUTHPRIV LOG_AUTH
+#endif
+
 typedef struct private_daemon_t private_daemon_t;
 
 /**
@@ -48,6 +56,21 @@ struct private_daemon_t {
         * Handler for kernel events
         */
        kernel_handler_t *kernel_handler;
+
+       /**
+        * A list of installed loggers (as logger_entry_t*)
+        */
+       linked_list_t *loggers;
+
+       /**
+        * Identifier used for syslog (in the openlog call)
+        */
+       char *syslog_identifier;
+
+       /**
+        * Mutex for configured loggers
+        */
+       mutex_t *mutex;
 };
 
 /**
@@ -78,6 +101,325 @@ static void dbg_bus(debug_t group, level_t level, char *fmt, ...)
 }
 
 /**
+ * Some metadata about configured loggers
+ */
+typedef struct {
+       /**
+        * Target of the logger (syslog facility or filename)
+        */
+       char *target;
+
+       /**
+        * TRUE if this is a file logger
+        */
+       bool file;
+
+       /**
+        * The actual logger
+        */
+       union {
+               sys_logger_t *sys;
+               file_logger_t *file;
+       } logger;
+
+} logger_entry_t;
+
+/**
+ * Destroy a logger entry
+ */
+static void logger_entry_destroy(logger_entry_t *this)
+{
+       if (this->file)
+       {
+               DESTROY_IF(this->logger.file);
+       }
+       else
+       {
+               DESTROY_IF(this->logger.sys);
+       }
+       free(this->target);
+       free(this);
+}
+
+/**
+ * Unregister and destroy a logger entry
+ */
+static void logger_entry_unregister_destroy(logger_entry_t *this)
+{
+       if (this->file)
+       {
+               charon->bus->remove_logger(charon->bus, &this->logger.file->logger);
+       }
+       else
+       {
+               charon->bus->remove_logger(charon->bus, &this->logger.sys->logger);
+       }
+       logger_entry_destroy(this);
+}
+
+/**
+ * Match a logger entry by target and whether it is a file or syslog logger
+ */
+static bool logger_entry_match(logger_entry_t *this, char *target, bool *file)
+{
+       return this->file == *file && streq(this->target, target);
+}
+
+/**
+ * Handle configured syslog identifier
+ *
+ * mutex must be locked when calling this function
+ */
+static void handle_syslog_identifier(private_daemon_t *this)
+{
+       char *identifier;
+
+       identifier = lib->settings->get_str(lib->settings, "%s.syslog.identifier",
+                                                                               NULL, charon->name);
+       if (identifier)
+       {       /* set identifier, which is prepended to each log line */
+               if (!this->syslog_identifier ||
+                       !streq(identifier, this->syslog_identifier))
+               {
+                       closelog();
+                       this->syslog_identifier = identifier;
+                       openlog(this->syslog_identifier, 0, 0);
+               }
+       }
+       else if (this->syslog_identifier)
+       {
+               closelog();
+               this->syslog_identifier = NULL;
+       }
+}
+
+/**
+ * Convert the given string into a syslog facility, returns -1 if the facility
+ * is not supported
+ */
+static int get_syslog_facility(char *facility)
+{
+       if (streq(facility, "daemon"))
+       {
+               return LOG_DAEMON;
+       }
+       else if (streq(facility, "auth"))
+       {
+               return LOG_AUTHPRIV;
+       }
+       return -1;
+}
+
+/**
+ * Returns an existing or newly created logger entry (if found, it is removed
+ * from the given linked list of existing loggers)
+ */
+static logger_entry_t *get_logger_entry(char *target, bool is_file_logger,
+                                                                               linked_list_t *existing)
+{
+       logger_entry_t *entry;
+
+       if (existing->find_first(existing, (void*)logger_entry_match,
+                                                       (void**)&entry, target, &is_file_logger) != SUCCESS)
+       {
+               INIT(entry,
+                       .target = strdup(target),
+                       .file = is_file_logger,
+               );
+               if (is_file_logger)
+               {
+                       entry->logger.file = file_logger_create(target);
+               }
+               else
+               {
+                       entry->logger.sys = sys_logger_create(get_syslog_facility(target));
+               }
+       }
+       else
+       {
+               existing->remove(existing, entry, NULL);
+       }
+       return entry;
+}
+
+/**
+ * Create or reuse a syslog logger
+ */
+static sys_logger_t *add_sys_logger(private_daemon_t *this, char *facility,
+                                                                       linked_list_t *current_loggers)
+{
+       logger_entry_t *entry;
+
+       entry = get_logger_entry(facility, FALSE, current_loggers);
+       this->loggers->insert_last(this->loggers, entry);
+       return entry->logger.sys;
+}
+
+/**
+ * Create or reuse a file logger
+ */
+static file_logger_t *add_file_logger(private_daemon_t *this, char *filename,
+                                                                         linked_list_t *current_loggers)
+{
+       logger_entry_t *entry;
+
+       entry = get_logger_entry(filename, TRUE, current_loggers);
+       this->loggers->insert_last(this->loggers, entry);
+       return entry->logger.file;
+}
+
+/**
+ * Load the given syslog logger configured in strongswan.conf
+ */
+static void load_sys_logger(private_daemon_t *this, char *facility,
+                                                       linked_list_t *current_loggers)
+{
+       sys_logger_t *sys_logger;
+       debug_t group;
+       level_t def;
+
+       if (get_syslog_facility(facility) == -1)
+       {
+               return;
+       }
+
+       sys_logger = add_sys_logger(this, facility, current_loggers);
+       sys_logger->set_options(sys_logger,
+                               lib->settings->get_bool(lib->settings, "%s.syslog.%s.ike_name",
+                                                                               FALSE, charon->name, facility));
+
+       def = lib->settings->get_int(lib->settings, "%s.syslog.%s.default", 1,
+                                                                charon->name, facility);
+       for (group = 0; group < DBG_MAX; group++)
+       {
+               sys_logger->set_level(sys_logger, group,
+                               lib->settings->get_int(lib->settings, "%s.syslog.%s.%N", def,
+                                                       charon->name, facility, debug_lower_names, group));
+       }
+       charon->bus->add_logger(charon->bus, &sys_logger->logger);
+}
+
+/**
+ * Load the given file logger configured in strongswan.conf
+ */
+static void load_file_logger(private_daemon_t *this, char *filename,
+                                                        linked_list_t *current_loggers)
+{
+       file_logger_t *file_logger;
+       debug_t group;
+       level_t def;
+       bool ike_name, flush_line, append;
+       char *time_format;
+
+       time_format = lib->settings->get_str(lib->settings,
+                                       "%s.filelog.%s.time_format", NULL, charon->name, filename);
+       ike_name = lib->settings->get_bool(lib->settings,
+                                       "%s.filelog.%s.ike_name", FALSE, charon->name, filename);
+       flush_line = lib->settings->get_bool(lib->settings,
+                                       "%s.filelog.%s.flush_line", FALSE, charon->name, filename);
+       append = lib->settings->get_bool(lib->settings,
+                                       "%s.filelog.%s.append", TRUE, charon->name, filename);
+
+       file_logger = add_file_logger(this, filename, current_loggers);
+       file_logger->set_options(file_logger, time_format, ike_name);
+       file_logger->open(file_logger, flush_line, append);
+
+       def = lib->settings->get_int(lib->settings, "%s.filelog.%s.default", 1,
+                                                                charon->name, filename);
+       for (group = 0; group < DBG_MAX; group++)
+       {
+               file_logger->set_level(file_logger, group,
+                               lib->settings->get_int(lib->settings, "%s.filelog.%s.%N", def,
+                                                       charon->name, filename, debug_lower_names, group));
+       }
+       charon->bus->add_logger(charon->bus, &file_logger->logger);
+}
+
+METHOD(daemon_t, load_loggers, void,
+       private_daemon_t *this, level_t levels[DBG_MAX], bool to_stderr)
+{
+       enumerator_t *enumerator;
+       linked_list_t *current_loggers;
+       char *target;
+
+       this->mutex->lock(this->mutex);
+       handle_syslog_identifier(this);
+       current_loggers = this->loggers;
+       this->loggers = linked_list_create();
+       enumerator = lib->settings->create_section_enumerator(lib->settings,
+                                                                                                       "%s.syslog", charon->name);
+       while (enumerator->enumerate(enumerator, &target))
+       {
+               load_sys_logger(this, target, current_loggers);
+       }
+       enumerator->destroy(enumerator);
+
+       enumerator = lib->settings->create_section_enumerator(lib->settings,
+                                                                                                       "%s.filelog", charon->name);
+       while (enumerator->enumerate(enumerator, &target))
+       {
+               load_file_logger(this, target, current_loggers);
+       }
+       enumerator->destroy(enumerator);
+
+       if (!this->loggers->get_count(this->loggers) && levels)
+       {       /* setup legacy style default loggers configured via command-line */
+               file_logger_t *file_logger;
+               sys_logger_t *sys_logger;
+               debug_t group;
+
+               sys_logger = add_sys_logger(this, "daemon", current_loggers);
+               file_logger = add_file_logger(this, "stdout", current_loggers);
+               file_logger->open(file_logger, FALSE, FALSE);
+
+               for (group = 0; group < DBG_MAX; group++)
+               {
+                       sys_logger->set_level(sys_logger, group, levels[group]);
+                       if (to_stderr)
+                       {
+                               file_logger->set_level(file_logger, group, levels[group]);
+                       }
+               }
+               charon->bus->add_logger(charon->bus, &sys_logger->logger);
+               charon->bus->add_logger(charon->bus, &file_logger->logger);
+
+               sys_logger = add_sys_logger(this, "auth", current_loggers);
+               sys_logger->set_level(sys_logger, DBG_ANY, LEVEL_AUDIT);
+               charon->bus->add_logger(charon->bus, &sys_logger->logger);
+       }
+       /* unregister and destroy any unused remaining loggers */
+       current_loggers->destroy_function(current_loggers,
+                                                                        (void*)logger_entry_unregister_destroy);
+       this->mutex->unlock(this->mutex);
+}
+
+METHOD(daemon_t, set_level, void,
+       private_daemon_t *this, debug_t group, level_t level)
+{
+       enumerator_t *enumerator;
+       logger_entry_t *entry;
+
+       /* we set the loglevel on ALL sys- and file-loggers */
+       this->mutex->lock(this->mutex);
+       enumerator = this->loggers->create_enumerator(this->loggers);
+       while (enumerator->enumerate(enumerator, &entry))
+       {
+               if (entry->file)
+               {
+                       entry->logger.file->set_level(entry->logger.file, group, level);
+                       charon->bus->add_logger(charon->bus, &entry->logger.file->logger);
+               }
+               else
+               {
+                       entry->logger.sys->set_level(entry->logger.sys, group, level);
+                       charon->bus->add_logger(charon->bus, &entry->logger.sys->logger);
+               }
+       }
+       enumerator->destroy(enumerator);
+       this->mutex->unlock(this->mutex);
+}
+
+/**
  * Clean up all daemon resources
  */
 static void destroy(private_daemon_t *this)
@@ -124,10 +466,8 @@ static void destroy(private_daemon_t *this)
        /* rehook library logging, shutdown logging */
        dbg = dbg_old;
        DESTROY_IF(this->public.bus);
-       this->public.file_loggers->destroy_offset(this->public.file_loggers,
-                                                                                       offsetof(file_logger_t, destroy));
-       this->public.sys_loggers->destroy_offset(this->public.sys_loggers,
-                                                                                       offsetof(sys_logger_t, destroy));
+       this->loggers->destroy_function(this->loggers, (void*)logger_entry_destroy);
+       this->mutex->destroy(this->mutex);
        free((void*)this->public.name);
        free(this);
 }
@@ -223,11 +563,13 @@ private_daemon_t *daemon_create(const char *name)
                .public = {
                        .initialize = _initialize,
                        .start = _start,
+                       .load_loggers = _load_loggers,
+                       .set_level = _set_level,
                        .bus = bus_create(),
-                       .file_loggers = linked_list_create(),
-                       .sys_loggers = linked_list_create(),
                        .name = strdup(name ?: "libcharon"),
                },
+               .loggers = linked_list_create(),
+               .mutex = mutex_create(MUTEX_TYPE_DEFAULT),
        );
        charon = &this->public;
        this->public.caps = capabilities_create();
index b67de77..06aa4ab 100644 (file)
@@ -157,8 +157,6 @@ typedef struct daemon_t daemon_t;
 #include <network/socket_manager.h>
 #include <control/controller.h>
 #include <bus/bus.h>
-#include <bus/listeners/file_logger.h>
-#include <bus/listeners/sys_logger.h>
 #include <sa/ike_sa_manager.h>
 #include <sa/trap_manager.h>
 #include <sa/shunt_manager.h>
@@ -248,16 +246,6 @@ struct daemon_t {
        bus_t *bus;
 
        /**
-        * A list of installed file_logger_t's
-        */
-       linked_list_t *file_loggers;
-
-       /**
-        * A list of installed sys_logger_t's
-        */
-       linked_list_t *sys_loggers;
-
-       /**
         * Controller to control the daemon
         */
        controller_t *controller;
@@ -307,6 +295,25 @@ struct daemon_t {
         */
        void (*start)(daemon_t *this);
 
+       /**
+        * Load/Reload loggers defined in strongswan.conf
+        *
+        * @param levels        optional debug levels used to create default loggers
+        *                                      if none are defined in strongswan.conf
+        * @param to_stderr     TRUE to log to stderr/stdout if no loggers are defined
+        *                                      in strongswan.conf
+        */
+       void (*load_loggers)(daemon_t *this, level_t levels[DBG_MAX],
+                                                bool to_stderr);
+
+       /**
+        * Set the log level for the given log group for all configured file- and
+        * syslog-loggers.
+        *
+        * @param group         log group
+        * @param level         log level
+        */
+       void (*set_level)(daemon_t *this, debug_t group, level_t level);
 };
 
 /**
index 241f0fb..28ebfac 100644 (file)
@@ -500,9 +500,6 @@ static void stroke_user_creds(private_stroke_socket_t *this,
 static void stroke_loglevel(private_stroke_socket_t *this,
                                                        stroke_msg_t *msg, FILE *out)
 {
-       enumerator_t *enumerator;
-       sys_logger_t *sys_logger;
-       file_logger_t *file_logger;
        debug_t group;
 
        pop_string(msg, &(msg->loglevel.type));
@@ -515,21 +512,7 @@ static void stroke_loglevel(private_stroke_socket_t *this,
                fprintf(out, "invalid type (%s)!\n", msg->loglevel.type);
                return;
        }
-       /* we set the loglevel on ALL sys- and file-loggers */
-       enumerator = charon->sys_loggers->create_enumerator(charon->sys_loggers);
-       while (enumerator->enumerate(enumerator, &sys_logger))
-       {
-               sys_logger->set_level(sys_logger, group, msg->loglevel.level);
-               charon->bus->add_logger(charon->bus, &sys_logger->logger);
-       }
-       enumerator->destroy(enumerator);
-       enumerator = charon->file_loggers->create_enumerator(charon->file_loggers);
-       while (enumerator->enumerate(enumerator, &file_logger))
-       {
-               file_logger->set_level(file_logger, group, msg->loglevel.level);
-               charon->bus->add_logger(charon->bus, &file_logger->logger);
-       }
-       enumerator->destroy(enumerator);
+       charon->set_level(charon, group, msg->loglevel.level);
 }
 
 /**