TT#84360 add new option to split multi-line log messages

Change-Id: Ie29301dbf5f704c4f3c87431e3c63fac761696d5
changes/48/41348/1
Richard Fuchs 5 years ago
parent 9d53e736b9
commit eae7f3a327

@ -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.

@ -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 },

@ -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;

@ -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 = "... ";
}

@ -74,6 +74,11 @@ Defaults to B<daemon>.
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.

Loading…
Cancel
Save