diff --git a/ChangeLog.md b/ChangeLog.md index 5608088..d0ca95c 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -38,6 +38,9 @@ repository history](https://github.com/ddclient/ddclient/commits/master). [#639](https://github.com/ddclient/ddclient/pull/639) * Updated sample systemd service unit file to improve logging in the systemd journal. [#669](https://github.com/ddclient/ddclient/pull/669) + * The second and subsequent lines in a multi-line log message are now prefixed + with a `|` character. + [#676](https://github.com/ddclient/ddclient/pull/676) ### Bug fixes diff --git a/ddclient.in b/ddclient.in index d9d600d..f6bf5ae 100755 --- a/ddclient.in +++ b/ddclient.in @@ -2398,14 +2398,15 @@ sub logmsg { chomp($buffer); my $prefix = $args{pfx}; - $prefix = sprintf "%-9s ", $prefix if $prefix; + $prefix = sprintf "%-9s ", $prefix if $prefix; if ($file) { $prefix .= "file $file"; $prefix .= ", line $lineno" if $lineno; - $prefix .= ": "; + $prefix .= ": "; } if ($prefix) { $buffer = "$prefix$buffer"; + $prefix =~ s/ $/| /; $buffer =~ s/\n/\n$prefix/g; } $buffer .= "\n"; diff --git a/t/logmsg.pl b/t/logmsg.pl index 47bc0cb..347a69e 100644 --- a/t/logmsg.pl +++ b/t/logmsg.pl @@ -55,49 +55,49 @@ my @test_cases = ( { desc => 'single-line prefix', args => [pfx => 'PFX:', 'foo'], - want => "PFX: foo\n", + want => "PFX: foo\n", }, { desc => 'multi-line prefix', args => [pfx => 'PFX:', "foo\nbar"], - want => "PFX: foo\nPFX: bar\n", + want => "PFX: foo\nPFX: | bar\n", }, { desc => 'single-line long prefix', args => [pfx => 'VERY LONG PREFIX:', 'foo'], - want => "VERY LONG PREFIX: foo\n", + want => "VERY LONG PREFIX: foo\n", }, { desc => 'multi-line long prefix', args => [pfx => 'VERY LONG PREFIX:', "foo\nbar"], - want => "VERY LONG PREFIX: foo\nVERY LONG PREFIX: bar\n", + want => "VERY LONG PREFIX: foo\nVERY LONG PREFIX:| bar\n", }, { desc => 'single line, no prefix, file', args => ['foo'], file => 'name', - want => "file name: foo\n", + want => "file name: foo\n", }, { desc => 'single line, no prefix, file, and line number', args => ['foo'], file => 'name', lineno => 42, - want => "file name, line 42: foo\n", + want => "file name, line 42: foo\n", }, { desc => 'single line, prefix, file, and line number', args => [pfx => 'PFX:', 'foo'], file => 'name', lineno => 42, - want => "PFX: file name, line 42: foo\n", + want => "PFX: file name, line 42: foo\n", }, { desc => 'multiple lines, prefix, file, and line number', args => [pfx => 'PFX:', "foo\nbar"], file => 'name', lineno => 42, - want => "PFX: file name, line 42: foo\nPFX: file name, line 42: bar\n", + want => "PFX: file name, line 42: foo\nPFX: file name, line 42:| bar\n", }, );