Improve logging.
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Fri, 17 Oct 2008 20:42:02 +0000 (22:42 +0200)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Fri, 17 Oct 2008 20:42:02 +0000 (22:42 +0200)
Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
common/common.c
common/common.h
common/rbl.c
common/server.c
pfix-srsd/main-srsd.c
postlicyd/main-postlicyd.c

index 63f0d9a..1b8cd98 100644 (file)
 
 #include "common.h"
 
-bool daemon_process  = true;
-int  log_level       = LOG_INFO;
-bool log_syslog      = false;
+bool daemon_process   = true;
+int  log_level        = LOG_INFO;
+bool log_syslog       = false;
+const char *log_state = "";
 
 static FILE *pidfile = NULL;
 
@@ -293,8 +294,9 @@ void common_register_exit(exitcall_t exitcall)
 
 static void common_shutdown(void)
 {
+    log_state = "stopping ";
     if (daemon_process && log_syslog) {
-        info("stopping...");
+        info("");
     }
     pidfile_close();
     for (int i = array_len(__exit) - 1 ; i >= 0 ; --i) {
@@ -309,6 +311,7 @@ void common_init(void)
     if (__ran) {
         return;
     }
+    log_state = "starting ";
     if (atexit(common_shutdown)) {
         fputs("Cannot hook my atexit function, quitting !\n", stderr);
         abort();
index 5e6757b..af393e5 100644 (file)
@@ -94,14 +94,14 @@ void common_init(void);
   : (L) == LOG_ALERT   ? "alert "                                  \
   : "???   " )
 
-#define __log(Level, Fmt, ...)                                    \
-    if (log_level >= Level) {                                     \
-        if (log_syslog) {                                         \
-            syslog(Level, Fmt, ##__VA_ARGS__);                    \
-        } else {                                                  \
-            fprintf(stderr, "[%s] " Fmt "\n",                     \
-                    __level_name(Level), ##__VA_ARGS__);          \
-        }                                                         \
+#define __log(Level, Fmt, ...)                                     \
+    if (log_level >= Level) {                                      \
+        if (log_syslog) {                                          \
+            syslog(Level, "%s" Fmt, log_state, ##__VA_ARGS__);     \
+        } else {                                                   \
+            fprintf(stderr, "[%s] %s" Fmt "\n",                    \
+                    __level_name(Level), log_state, ##__VA_ARGS__);\
+        }                                                          \
     }
 
 #define debug(Fmt, ...)  __log(LOG_DEBUG,   Fmt, ##__VA_ARGS__)
@@ -118,6 +118,7 @@ void common_init(void);
 
 extern int          log_level;
 extern bool         log_syslog;
+extern const char  *log_state;
 
 void common_sighandler(int sig);
 
index c118f15..416f222 100644 (file)
@@ -111,10 +111,7 @@ static void rbl_callback(void *arg, int err, struct ub_result *result)
         *context->result = RBL_FOUND;
     }
     if (context->call != NULL) {
-        debug("calling callback");
         context->call(context->result, context->data);
-    } else {
-        debug("no callback defined");
     }
     ub_resolve_free(result);
     rbl_context_release(context);
index f142cb7..a07355e 100644 (file)
@@ -176,8 +176,6 @@ static void client_cb(EV_P_ struct ev_io *w, int events)
 {
     client_t *server = (client_t*)w;
 
-    debug("Entering client_cb for %p, %d (%d | %d)", w, events, EV_WRITE, EV_READ);
-
     if (events & EV_WRITE && server->obuf.len) {
         if (buffer_write(&server->obuf, server->io.fd) < 0) {
             client_release(server);
@@ -319,9 +317,14 @@ module_exit(server_shutdown);
 
 static void refresh_cb(EV_P_ struct ev_signal *w, int event)
 {
+    log_state = "refreshing ";
     if (!gl_config_refresh(gl_config)) {
         ev_unloop(EV_A_ EVUNLOOP_ALL);
+        info("failed");
+    } else {
+        info("done");
     }
+    log_state = "";
 }
 
 static void exit_cb(EV_P_ struct ev_signal *w, int event)
@@ -351,6 +354,7 @@ int server_loop(start_client_t starter, delete_client_t deleter,
     ev_signal_init(&ev_sigterm, exit_cb, SIGTERM);
     ev_signal_start(gl_loop, &ev_sigterm);
 
+    log_state = "";
     info("entering processing loop");
     ev_loop(gl_loop, 0);
     info("exit requested");
index acaa3fc..e95ffd9 100644 (file)
@@ -304,7 +304,7 @@ int main(int argc, char *argv[])
         return EXIT_FAILURE;
     }
 
-    info("starting %s v%s...", DAEMON_NAME, DAEMON_VERSION);
+    info("%s v%s...", DAEMON_NAME, DAEMON_VERSION);
 
     config.domain = argv[optind];
     config.srs = srs_read_secrets(argv[optind + 1]);
index 86d1400..7d7d8df 100644 (file)
@@ -329,7 +329,7 @@ int main(int argc, char *argv[])
         return EXIT_FAILURE;
     }
 
-    info("starting %s v%s...", DAEMON_NAME, DAEMON_VERSION);
+    info("%s v%s...", DAEMON_NAME, DAEMON_VERSION);
 
     if (pidfile_open(pidfile) < 0) {
         crit("unable to write pidfile %s", pidfile);