Fix restart and code review (#912)

On start the daemon may write an empty line.
Log as warning non managed log level.

Thanks Andrew .F. for pointers
This commit is contained in:
S.F 2020-11-18 12:30:25 -05:00 committed by GitHub
parent f818ab497b
commit a02a12f639
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3,16 +3,20 @@ use Sys::Syslog qw(:standard :macros);
openlog($ARGV[0], "pid", "daemon");
my %lvl_map = (
'panic' => LOG_EMERG,
'fatal' => LOG_CRIT,
'error' => LOG_ERR,
'warn' => LOG_WARNING,
'info' => LOG_INFO,
);
while (my $l = <STDIN>) {
my @d = split /\t/, $l;
# go level : "INFO", "WARN", "ERROR", "FATAL", "PANIC":
my $lvl = $d[0];
$lvl = LOG_EMERG if ($lvl eq 'panic');
$lvl = 'crit' if ($lvl eq 'fatal');
$lvl = 'err' if ($lvl eq 'error');
$lvl = 'warning' if ($lvl eq 'warn');
chomp $d[2];
syslog( $lvl, $d[2] );
my ($lvl, undef, $message) = split /\t/, $_, 3;
next unless $message;
$lvl = $lvl_map{ lc $lvl } || LOG_WARNING;
chomp $message;
syslog( $lvl, $message );
}
closelog();