From 21fef94beeba672fff22406d863a5423a27bed23 Mon Sep 17 00:00:00 2001 From: Apollon Oikonomopoulos Date: Thu, 17 Apr 2014 13:39:29 +0300 Subject: [PATCH 14/15] MINOR: systemd wrapper: improve logging MINOR: systemd wrapper: improve logging Use standard error for logging messages, as it seems that this gets messages to the systemd journal more reliably. Also use systemd's support for specifying log levels via stderr to apply different levels to messages. --- src/haproxy-systemd-wrapper.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/haproxy-systemd-wrapper.c b/src/haproxy-systemd-wrapper.c index e373483d5085..d4baa90c266e 100644 --- a/src/haproxy-systemd-wrapper.c +++ b/src/haproxy-systemd-wrapper.c @@ -19,6 +19,8 @@ #include #define REEXEC_FLAG "HAPROXY_SYSTEMD_REEXEC" +#define SD_DEBUG "<7>" +#define SD_NOTICE "<5>" static char *pid_file = "/run/haproxy.pid"; static int wrapper_argc; @@ -68,10 +70,10 @@ static void spawn_haproxy(char **pid_strv, int nb_pid) } argv[argno] = NULL; - printf("%s", "haproxy-systemd-wrapper: executing "); + fprintf(stderr, SD_DEBUG "haproxy-systemd-wrapper: executing "); for (i = 0; argv[i]; ++i) - printf("%s ", argv[i]); - puts(""); + fprintf(stderr, "%s ", argv[i]); + fprintf(stderr, "\n"); execv(argv[0], argv); exit(0); @@ -104,7 +106,7 @@ static int read_pids(char ***pid_strv) static void sigusr2_handler(int signum __attribute__((unused))) { setenv(REEXEC_FLAG, "1", 1); - printf("haproxy-systemd-wrapper: re-executing\n"); + fprintf(stderr, SD_NOTICE "haproxy-systemd-wrapper: re-executing\n"); execv(wrapper_argv[0], wrapper_argv); } @@ -117,7 +119,7 @@ static void sigint_handler(int signum __attribute__((unused))) for (i = 0; i < nb_pid; ++i) { pid = atoi(pid_strv[i]); if (pid > 0) { - printf("haproxy-systemd-wrapper: SIGINT -> %d\n", pid); + fprintf(stderr, SD_DEBUG "haproxy-systemd-wrapper: SIGINT -> %d\n", pid); kill(pid, SIGINT); free(pid_strv[i]); } @@ -180,6 +182,7 @@ int main(int argc, char **argv) while (-1 != wait(&status) || errno == EINTR) ; - printf("haproxy-systemd-wrapper: exit, haproxy RC=%d\n", status); + fprintf(stderr, SD_NOTICE "haproxy-systemd-wrapper: exit, haproxy RC=%d\n", + status); return EXIT_SUCCESS; } -- 1.8.4.5