Improve logging again.
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Mon, 6 Oct 2008 20:24:54 +0000 (22:24 +0200)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Mon, 6 Oct 2008 20:24:54 +0000 (22:24 +0200)
Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
common/common.c
common/common.h
common/server.c
postlicyd/main-postlicyd.c

index e9e4f2e..aa9e5ea 100644 (file)
@@ -297,7 +297,7 @@ extern exitcall_t __madexit[];
 
 static void common_shutdown(void)
 {
-    if (daemon_process) {
+    if (daemon_process && log_syslog) {
         info("stopping...");
     }
     pidfile_close();
index 896eacc..0b0cd85 100644 (file)
@@ -57,7 +57,6 @@
 
 #include "mem.h"
 
-
 #define __tostr(x)  #x
 #define STR(x)      __tostr(x)
 
@@ -73,13 +72,23 @@ typedef void (*exitcall_t)(void);
 #define likely(expr)    __builtin_expect((expr) != 0, 1)
 #define unlikely(expr)  __builtin_expect((expr) != 0, 0)
 
+#define __level_name(L)                                            \
+  ( (L) == LOG_DEBUG   ? "debug "                                  \
+  : (L) == LOG_NOTICE  ? "notice"                                  \
+  : (L) == LOG_INFO    ? "info  "                                  \
+  : (L) == LOG_WARNING ? "warn  "                                  \
+  : (L) == LOG_ERR     ? "error "                                  \
+  : (L) == LOG_CRIT    ? "crit  "                                  \
+  : (L) == LOG_ALERT   ? "alert "                                  \
+  : "???   " )
+
 #define __log(Level, Fmt, ...)                                    \
     if (log_level >= Level) {                                     \
         if (log_syslog) {                                         \
             syslog(Level, Fmt, ##__VA_ARGS__);                    \
         } else {                                                  \
-            fprintf(stderr, "[%d] " Fmt "\n",                     \
-                    Level, ##__VA_ARGS__);                        \
+            fprintf(stderr, "[%s] " Fmt "\n",                     \
+                    __level_name(Level), ##__VA_ARGS__);          \
         }                                                         \
     }
 
@@ -124,7 +133,6 @@ static inline void common_startup(void)
     signal(SIGTERM, &common_sighandler);
     signal(SIGHUP,  &common_sighandler);
     signal(SIGSEGV, &common_sighandler);
-    info("starting");
 }
 
 
index ea1df31..78af625 100644 (file)
@@ -136,16 +136,19 @@ static int start_client(server_t *server, start_client_t starter,
 
 int server_loop(start_client_t starter, delete_client_t deleter,
                 run_client_t runner, refresh_t refresh, void* config) {
+    info("entering processing loop");
     while (!sigint) {
         struct epoll_event evts[1024];
         int n;
 
         if (sighup && refresh) {
             sighup = false;
+            info("refreshing...");
             if (!refresh(config)) {
                 crit("error while refreshing configuration");
                 return EXIT_FAILURE;
             }
+            info("refresh done, processing loop restarts");
         }
 
         n = epoll_select(evts, countof(evts), -1);
@@ -183,5 +186,6 @@ int server_loop(start_client_t starter, delete_client_t deleter,
             }
         }
     }
+    info("exit requested");
     return EXIT_SUCCESS;
 }
index 9bdc391..751ff5a 100644 (file)
@@ -45,6 +45,7 @@
 #include "config.h"
 
 #define DAEMON_NAME             "postlicyd"
+#define DAEMON_VERSION          "0.2"
 #define DEFAULT_PORT            10000
 #define RUNAS_USER              "nobody"
 #define RUNAS_GROUP             "nogroup"
@@ -199,11 +200,17 @@ int main(int argc, char *argv[])
         }
     }
 
+    if (!daemonize) {
+        log_syslog = false;
+    }
+
     if (argc - optind != 1) {
         usage();
         return EXIT_FAILURE;
     }
 
+    info("starting %s v%s...", DAEMON_NAME, DAEMON_VERSION);
+
     if (pidfile_open(pidfile) < 0) {
         crit("unable to write pidfile %s", pidfile);
         return EXIT_FAILURE;