logging: Change multi-line log message designation style
Before, the first line of a multi-line log message was prefixed with a space while all subsequent messages were prefixed with `|`. Now the first line is prefixed with `>` and all subsequent lines with a space. This makes it easier to quickly discern message boundaries.
This commit is contained in:
parent
bd437a0abf
commit
6aa68f72a7
3 changed files with 15 additions and 13 deletions
|
@ -68,9 +68,10 @@ 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.
|
||||
* The second and subsequent lines in a multi-line log message now have a
|
||||
different prefix to distinguish them from separate log messages.
|
||||
[#676](https://github.com/ddclient/ddclient/pull/676)
|
||||
[#719](https://github.com/ddclient/ddclient/pull/719)
|
||||
* `emailonly`: New `protocol` option that simply emails you when your IP
|
||||
address changes. [#654](https://github.com/ddclient/ddclient/pull/654)
|
||||
* `he.net`: Added support for updating Hurricane Electric records.
|
||||
|
|
|
@ -2364,15 +2364,16 @@ sub logmsg {
|
|||
chomp($buffer);
|
||||
|
||||
my $prefix = $args{pfx};
|
||||
$prefix = sprintf "%-9s ", $prefix if $prefix;
|
||||
$prefix = sprintf "%-8s ", $prefix if $prefix;
|
||||
if ($file) {
|
||||
$prefix .= "file $file";
|
||||
$prefix .= ", line $lineno" if $lineno;
|
||||
$prefix .= ": ";
|
||||
$prefix .= ": ";
|
||||
}
|
||||
if ($prefix) {
|
||||
$prefix .= "> ";
|
||||
$buffer = "$prefix$buffer";
|
||||
$prefix =~ s/ $/| /;
|
||||
$prefix =~ s/> $/ /;
|
||||
$buffer =~ s/\n/\n$prefix/g;
|
||||
}
|
||||
$buffer .= "\n";
|
||||
|
|
16
t/logmsg.pl
16
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",
|
||||
},
|
||||
);
|
||||
|
||||
|
|
Loading…
Reference in a new issue