From 86ddff4a0aa0f3cc316a589f97d3c62663bd2719 Mon Sep 17 00:00:00 2001 From: Richard Cochran Date: Sun, 8 Jan 2012 11:44:42 +0100 Subject: [PATCH] Print messages to the syslog by default. Signed-off-by: Richard Cochran --- print.c | 18 +++++++++++++++++- print.h | 2 ++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/print.c b/print.c index 00af86f..0ab1e6a 100644 --- a/print.c +++ b/print.c @@ -19,18 +19,30 @@ #include #include #include +#include #include #include "print.h" -static int verbose = 1; +static int verbose; static int print_level = LOG_INFO; +static int use_syslog = 1; + +void print_no_syslog(void) +{ + use_syslog = 0; +} void print_set_level(int level) { print_level = level; } +void print_verbose(void) +{ + verbose = 1; +} + void print(int level, char const *format, ...) { pid_t pid; @@ -48,5 +60,9 @@ void print(int level, char const *format, ...) if (verbose) { fprintf(stdout, "ptp4l[%d]: %s\n", pid, buf); + fflush(stdout); + } + if (use_syslog) { + syslog(level, "[%d] %s", pid, buf); } } diff --git a/print.h b/print.h index eeb868e..1b42b2b 100644 --- a/print.h +++ b/print.h @@ -24,7 +24,9 @@ void print(int level, char const *format, ...); +void print_no_syslog(void); void print_set_level(int level); +void print_verbose(void); #define pr_emerg(x...) print(LOG_EMERG, x) #define pr_alert(x...) print(LOG_ALERT, x)