Skip to content

Commit

Permalink
Fix restart and code review (VictoriaMetrics#912)
Browse files Browse the repository at this point in the history
On start the daemon may write an empty line.
Log as warning non managed log level.

Thanks Andrew .F. for pointers
  • Loading branch information
dohnuts authored Nov 18, 2020
1 parent f818ab4 commit a02a12f
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions ports/OpenBSD/VictoriaMetrics/pkg/vmlogger.pl
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@

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();

0 comments on commit a02a12f

Please sign in to comment.