Add setting to direct logs to syslog, STDERR or STDOUT

This commit is contained in:
Mike Brady
2020-05-27 16:21:35 +01:00
parent 2d7ae4bce9
commit 6406c296f5
4 changed files with 38 additions and 4 deletions
+19 -2
View File
@@ -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;
+4 -1
View File
@@ -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
+2 -1
View 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
+13
View 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)