]> git.ipfire.org Git - thirdparty/shairport-sync.git/commitdiff
Add setting to direct logs to syslog, STDERR or STDOUT
authorMike Brady <mikebradydublin@icloud.com>
Wed, 27 May 2020 15:21:35 +0000 (16:21 +0100)
committerMike Brady <mikebradydublin@icloud.com>
Wed, 27 May 2020 15:21:35 +0000 (16:21 +0100)
common.c
common.h
scripts/shairport-sync.conf
shairport.c

index 74f8986978c3a2340f399cbc0dec54947be38e91..bb824ca68bb3fb3cfab581a587d0274b6a11f915 100644 (file)
--- 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;
 
index b964e051136f3f4c51e084d8af20b228fff9dab4..df4243a9590cd69a30b867c14fd6decbc2d9482f 100644 (file)
--- 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
 
index 09098fbc0ac86dd22552389020ac87a568a44378..1b6105cb40ffd32730e87bbbb4ddd9ee65f26811 100644 (file)
@@ -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 = <number>; // Use this optional advanced setting to set the alsa period size near to this value
 //     buffer_size = <number>; // 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
index 0ad40ad8e87c1453be112d3129a668699a27ecfe..fc1643ab00d6e4ea76d88c126b7af4bbc81f9454 100644 (file)
@@ -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)