logging: Rename pfx
to label
This is to prepare for a general log prefix mechanism to improve log readability.
This commit is contained in:
parent
015600d72f
commit
3262dd0952
2 changed files with 29 additions and 28 deletions
17
ddclient.in
17
ddclient.in
|
@ -2348,7 +2348,7 @@ my $_in_logmsg = 0;
|
|||
sub logmsg {
|
||||
my %args = (
|
||||
msg => '',
|
||||
pfx => '',
|
||||
label => '',
|
||||
fh => *STDERR,
|
||||
email => 0, # If truthy, the message is also included in the next email.
|
||||
(@_ % 2) ? (msg => pop) : (),
|
||||
|
@ -2357,7 +2357,7 @@ sub logmsg {
|
|||
my $buffer = $args{msg};
|
||||
chomp($buffer);
|
||||
|
||||
my $prefix = $args{pfx};
|
||||
my $prefix = $args{label};
|
||||
$prefix = sprintf "%-8s ", $prefix if $prefix;
|
||||
if ($file) {
|
||||
$prefix .= "file $file";
|
||||
|
@ -2383,12 +2383,13 @@ sub logmsg {
|
|||
}
|
||||
}
|
||||
sub _logmsg_fmt { return (@_ > 1) ? sprintf(shift, @_) : shift; }
|
||||
sub info { logmsg(email => 1, pfx => 'INFO:', _logmsg_fmt(@_)) if opt('verbose'); }
|
||||
sub debug { logmsg( pfx => 'DEBUG:', _logmsg_fmt(@_)) if opt('debug'); }
|
||||
sub warning { logmsg(email => 1, pfx => 'WARNING:', _logmsg_fmt(@_)); }
|
||||
sub fatal { logmsg(email => 1, pfx => 'FATAL:', _logmsg_fmt(@_)); sendmail(); exit(1); }
|
||||
sub success { logmsg(email => 1, pfx => 'SUCCESS:', _logmsg_fmt(@_)); }
|
||||
sub failed { logmsg(email => 1, pfx => 'FAILED:', _logmsg_fmt(@_)); $result = 'FAILED'; }
|
||||
sub info { logmsg(email => 1, label => 'INFO:', _logmsg_fmt(@_)) if opt('verbose'); }
|
||||
sub debug { logmsg( label => 'DEBUG:', _logmsg_fmt(@_)) if opt('debug'); }
|
||||
sub warning { logmsg(email => 1, label => 'WARNING:', _logmsg_fmt(@_)); }
|
||||
sub fatal { logmsg(email => 1, label => 'FATAL:', _logmsg_fmt(@_)); sendmail(); exit(1); }
|
||||
sub success { logmsg(email => 1, label => 'SUCCESS:', _logmsg_fmt(@_)); }
|
||||
sub failed { logmsg(email => 1, label => 'FAILED:', _logmsg_fmt(@_)); $result = 'FAILED'; }
|
||||
|
||||
sub prettytime { return scalar(localtime(shift)); }
|
||||
|
||||
sub prettyinterval {
|
||||
|
|
40
t/logmsg.pl
40
t/logmsg.pl
|
@ -53,51 +53,51 @@ my @test_cases = (
|
|||
want => "foo\n",
|
||||
},
|
||||
{
|
||||
desc => 'single-line prefix',
|
||||
args => [pfx => 'PFX:', 'foo'],
|
||||
want => "PFX: > foo\n",
|
||||
desc => 'single-line label',
|
||||
args => [label => 'LBL:', 'foo'],
|
||||
want => "LBL: > foo\n",
|
||||
},
|
||||
{
|
||||
desc => 'multi-line prefix',
|
||||
args => [pfx => 'PFX:', "foo\nbar"],
|
||||
want => "PFX: > foo\nPFX: bar\n",
|
||||
desc => 'multi-line label',
|
||||
args => [label => 'LBL:', "foo\nbar"],
|
||||
want => "LBL: > foo\nLBL: bar\n",
|
||||
},
|
||||
{
|
||||
desc => 'single-line long prefix',
|
||||
args => [pfx => 'VERY LONG PREFIX:', 'foo'],
|
||||
want => "VERY LONG PREFIX: > foo\n",
|
||||
desc => 'single-line long label',
|
||||
args => [label => 'VERY LONG LABEL:', 'foo'],
|
||||
want => "VERY LONG LABEL: > foo\n",
|
||||
},
|
||||
{
|
||||
desc => 'multi-line long prefix',
|
||||
args => [pfx => 'VERY LONG PREFIX:', "foo\nbar"],
|
||||
want => "VERY LONG PREFIX: > foo\nVERY LONG PREFIX: bar\n",
|
||||
desc => 'multi-line long label',
|
||||
args => [label => 'VERY LONG LABEL:', "foo\nbar"],
|
||||
want => "VERY LONG LABEL: > foo\nVERY LONG LABEL: bar\n",
|
||||
},
|
||||
{
|
||||
desc => 'single line, no prefix, file',
|
||||
desc => 'single line, no label, file',
|
||||
args => ['foo'],
|
||||
file => 'name',
|
||||
want => "file name: > foo\n",
|
||||
},
|
||||
{
|
||||
desc => 'single line, no prefix, file, and line number',
|
||||
desc => 'single line, no label, file, and line number',
|
||||
args => ['foo'],
|
||||
file => 'name',
|
||||
lineno => 42,
|
||||
want => "file name, line 42: > foo\n",
|
||||
},
|
||||
{
|
||||
desc => 'single line, prefix, file, and line number',
|
||||
args => [pfx => 'PFX:', 'foo'],
|
||||
desc => 'single line, label, file, and line number',
|
||||
args => [label => 'LBL:', 'foo'],
|
||||
file => 'name',
|
||||
lineno => 42,
|
||||
want => "PFX: file name, line 42: > foo\n",
|
||||
want => "LBL: file name, line 42: > foo\n",
|
||||
},
|
||||
{
|
||||
desc => 'multiple lines, prefix, file, and line number',
|
||||
args => [pfx => 'PFX:', "foo\nbar"],
|
||||
desc => 'multiple lines, label, file, and line number',
|
||||
args => [label => 'LBL:', "foo\nbar"],
|
||||
file => 'name',
|
||||
lineno => 42,
|
||||
want => "PFX: file name, line 42: > foo\nPFX: file name, line 42: bar\n",
|
||||
want => "LBL: file name, line 42: > foo\nLBL: file name, line 42: bar\n",
|
||||
},
|
||||
);
|
||||
|
||||
|
|
Loading…
Reference in a new issue