From: Florent Bruneau Date: Fri, 17 Oct 2008 20:42:02 +0000 (+0200) Subject: Improve logging. X-Git-Url: http://git.madism.org/?a=commitdiff_plain;h=af645f579c2652e6a095876048565d03a9434286;p=apps%2Fpfixtools.git Improve logging. Signed-off-by: Florent Bruneau --- diff --git a/common/common.c b/common/common.c index 63f0d9a..1b8cd98 100644 --- a/common/common.c +++ b/common/common.c @@ -41,9 +41,10 @@ #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(); diff --git a/common/common.h b/common/common.h index 5e6757b..af393e5 100644 --- a/common/common.h +++ b/common/common.h @@ -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); diff --git a/common/rbl.c b/common/rbl.c index c118f15..416f222 100644 --- a/common/rbl.c +++ b/common/rbl.c @@ -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); diff --git a/common/server.c b/common/server.c index f142cb7..a07355e 100644 --- a/common/server.c +++ b/common/server.c @@ -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"); diff --git a/pfix-srsd/main-srsd.c b/pfix-srsd/main-srsd.c index acaa3fc..e95ffd9 100644 --- a/pfix-srsd/main-srsd.c +++ b/pfix-srsd/main-srsd.c @@ -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]); diff --git a/postlicyd/main-postlicyd.c b/postlicyd/main-postlicyd.c index 86d1400..7d7d8df 100644 --- a/postlicyd/main-postlicyd.c +++ b/postlicyd/main-postlicyd.c @@ -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);