diff --git a/daemon/rtpengine.pod b/daemon/rtpengine.pod index 4f97587f5..902fb63c2 100644 --- a/daemon/rtpengine.pod +++ b/daemon/rtpengine.pod @@ -251,6 +251,11 @@ Write SRTP keys to error log instead of debug log. Log to stderr instead of syslog. Only useful in combination with B<--foreground>. +=item B<--split-logs> + +Split multi-line log messages into individual log messages so that each +line receives its own log line prefix. + =item B<--no-log-timestamps> Don't add timestamps to log lines written to stderr. diff --git a/lib/auxlib.c b/lib/auxlib.c index 82065bec8..6514f5e71 100644 --- a/lib/auxlib.c +++ b/lib/auxlib.c @@ -147,6 +147,7 @@ void config_load(int *argc, char ***argv, GOptionEntry *app_entries, const char { "log-facility", 0, 0, G_OPTION_ARG_STRING, &rtpe_common_config_ptr->log_facility, "Syslog facility to use for logging", "daemon|local0|...|local7"}, { "log-level", 'L', 0, G_OPTION_ARG_INT, (void *)&rtpe_common_config_ptr->log_level,"Mask log priorities above this level","INT" }, { "log-stderr", 'E', 0, G_OPTION_ARG_NONE, &rtpe_common_config_ptr->log_stderr, "Log on stderr instead of syslog", NULL }, + { "split-logs", 0, 0, G_OPTION_ARG_NONE, &rtpe_common_config_ptr->split_logs, "Split multi-line log messages", NULL }, { "no-log-timestamps", 0, 0, G_OPTION_ARG_NONE, &rtpe_common_config_ptr->no_log_timestamps,"Drop timestamps from log lines to stderr",NULL }, { "log-mark-prefix", 0, 0, G_OPTION_ARG_STRING, &rtpe_common_config_ptr->log_mark_prefix,"Prefix for sensitive log info", NULL }, { "log-mark-suffix", 0, 0, G_OPTION_ARG_STRING, &rtpe_common_config_ptr->log_mark_suffix,"Suffix for sensitive log info", NULL }, diff --git a/lib/auxlib.h b/lib/auxlib.h index d5c7dc0ba..095d21eba 100644 --- a/lib/auxlib.h +++ b/lib/auxlib.h @@ -18,6 +18,7 @@ struct rtpengine_common_config { char *log_facility; volatile int log_level; int log_stderr; + int split_logs; int no_log_timestamps; char *log_mark_prefix; char *log_mark_suffix; diff --git a/lib/loglib.c b/lib/loglib.c index 9cf7edb67..888b81425 100644 --- a/lib/loglib.c +++ b/lib/loglib.c @@ -180,10 +180,30 @@ void __vpilog(int prio, const char *prefix, const char *fmt, va_list ap) { piece = msg; - while (max_log_line_length && len > max_log_line_length) { - write_log(xprio, "%s: %s%s%.*s ...", prio_prefix, prefix, infix, max_log_line_length, piece); - len -= max_log_line_length; - piece += max_log_line_length; + while (1) { + unsigned int max_line_len = max_log_line_length; + unsigned int skip_len = max_line_len; + if (rtpe_common_config_ptr->split_logs) { + char *newline = strchr(piece, '\n'); + if (newline) { + unsigned int nl_pos = newline - piece; + if (!max_line_len || nl_pos < max_line_len) { + max_line_len = nl_pos; + skip_len = nl_pos + 1; + if (nl_pos >= 1 && piece[nl_pos-1] == '\r') + max_line_len--; + } + } + } + + if (!max_line_len) + break; + if (len <= max_line_len) + break; + + write_log(xprio, "%s: %s%s%.*s ...", prio_prefix, prefix, infix, max_line_len, piece); + len -= skip_len; + piece += skip_len; infix = "... "; } diff --git a/recording-daemon/rtpengine-recording.pod b/recording-daemon/rtpengine-recording.pod index 3d20f04ba..e561e27c3 100644 --- a/recording-daemon/rtpengine-recording.pod +++ b/recording-daemon/rtpengine-recording.pod @@ -74,6 +74,11 @@ Defaults to B. Log to stderr instead of syslog. Only useful in combination with B<--foreground>. +=item B<--split-logs> + +Split multi-line log messages into individual log messages so that each +line receives its own log line prefix. + =item B<--no-log-timestamps> Don't add timestamps to log lines written to stderr.