From: Mike Brady Date: Wed, 27 May 2020 15:21:35 +0000 (+0100) Subject: Add setting to direct logs to syslog, STDERR or STDOUT X-Git-Tag: 3.3.7d12~73 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6406c296f587218d9ec53a57da30be882aef8fd9;p=thirdparty%2Fshairport-sync.git Add setting to direct logs to syslog, STDERR or STDOUT --- diff --git a/common.c b/common.c index 74f89869..bb824ca6 100644 --- a/common.c +++ b/common.c @@ -121,7 +121,7 @@ static void (*sps_log)(int prio, const char *t, ...) = daemon_log; static void (*sps_log)(int prio, const char *t, ...) = syslog; #endif -void do_sps_log(__attribute__((unused)) int prio, const char *t, ...) { +void do_sps_log_to_stderr(__attribute__((unused)) int prio, const char *t, ...) { char s[1024]; va_list args; va_start(args, t); @@ -130,7 +130,24 @@ void do_sps_log(__attribute__((unused)) int prio, const char *t, ...) { fprintf(stderr, "%s\n", s); } -void log_to_stderr() { sps_log = do_sps_log; } +void do_sps_log_to_stdout(__attribute__((unused)) int prio, const char *t, ...) { + char s[1024]; + va_list args; + va_start(args, t); + vsnprintf(s, sizeof(s), t, args); + va_end(args); + fprintf(stdout, "%s\n", s); +} + +void log_to_stderr() { sps_log = do_sps_log_to_stderr; } +void log_to_stdout() { sps_log = do_sps_log_to_stdout; } +void log_to_syslog() { +#ifdef CONFIG_LIBDAEMON + sps_log = daemon_log; +#else + sps_log = syslog; +#endif +} shairport_cfg config; diff --git a/common.h b/common.h index b964e051..df4243a9 100644 --- a/common.h +++ b/common.h @@ -295,7 +295,10 @@ uint16_t nctohs(const uint8_t *p); // read 2 characters from *p and do ntohs on void memory_barrier(); -void log_to_stderr(); // call this to director logging to stderr; +void log_to_stderr(); // call this to direct logging to stderr; +void log_to_stdout(); // call this to direct logging to stdout; +void log_to_syslog(); // call this to direct logging to the system log; + // true if Shairport Sync is supposed to be sending output to the output device, false otherwise diff --git a/scripts/shairport-sync.conf b/scripts/shairport-sync.conf index 09098fbc..1b6105cb 100644 --- a/scripts/shairport-sync.conf +++ b/scripts/shairport-sync.conf @@ -102,7 +102,7 @@ alsa = // output_rate = "auto"; // can be "auto", 44100, 88200, 176400 or 352800, but the device must have the capability. // output_format = "auto"; // can be "auto", "U8", "S8", "S16", "S16_LE", "S16_BE", "S24", "S24_LE", "S24_BE", "S24_3LE", "S24_3BE", "S32", "S32_LE" or "S32_BE" but the device must have the capability. Except where stated using (*LE or *BE), endianness matches that of the processor. -// disable_synchronization = "no"; // Set to "yes" to disable synchronization. Default is "no" This is really meant for troubleshooting. +// disable_synchronization = "no"; // Set to "yes" to disable synchronization. Default is "no" This is really meant for troubleshootingG. // period_size = ; // Use this optional advanced setting to set the alsa period size near to this value // buffer_size = ; // Use this optional advanced setting to set the alsa buffer size near to this value @@ -245,6 +245,7 @@ mqtt = diagnostics = { // disable_resend_requests = "no"; // set this to yes to stop Shairport Sync from requesting the retransmission of missing packets. Default is "no". +// log_output_to = "syslog"; // set this to "syslog" (default), "STDERR" or "STDOUT" to specify were all logs, statistics and diagnostic messages are written to. // statistics = "no"; // set to "yes" to print statistics in the log // log_verbosity = 0; // "0" means no debug verbosity, "3" is most verbose. // log_show_file_and_line = "yes"; // set this to yes if you want the file and line number of the message source in the log file diff --git a/shairport.c b/shairport.c index 0ad40ad8..fc1643ab 100644 --- a/shairport.c +++ b/shairport.c @@ -662,6 +662,19 @@ int parse_options(int argc, char **argv) { dvalue); } + /* Get the diagnostics output default. */ + if (config_lookup_string(config.cfg, "diagnostics.log_output_to", &str)) { + if (strcasecmp(str, "syslog") == 0) + log_to_syslog(); + else if (strcasecmp(str, "stdout") == 0) { + log_to_stdout(); + } else if (strcasecmp(str, "stderr") == 0) { + log_to_stderr(); + } else { + log_to_syslog(); + die("Invalid diagnostics log_output_to setting \"%s\". It should be \"syslog\", \"STDERR\" or \"STDOUT\". It is set to syslog."); + } + } /* Get the ignore_volume_control setting. */ if (config_lookup_string(config.cfg, "general.ignore_volume_control", &str)) { if (strcasecmp(str, "no") == 0)