All the files

This commit is contained in:
2024-03-09 15:36:42 +01:00
parent 58e88da2d8
commit 08b6b503a6
22 changed files with 1721 additions and 0 deletions

35
lib/logger.pm Normal file
View File

@@ -0,0 +1,35 @@
package My::parser::logger;
use strict;
use warnings;
sub new {
my $class = shift;
my $config = shift;
my $self = {};
bless ($self, $class);
$self->{'config'} = $config;
return $self;
}
sub log {
my $self = shift;
my $str = shift;
my $fh = $self->{'logfh'};
return 0 unless($str);
print $fh localtime(time).': '.$str."\n";
return 1;
}
sub reload_log {
my $self = shift;
my $file = $self->{'config'}->get_as_single_val('config','logfile');
die 'No output logfile' unless($file);
close($self->{'logfh'}) if($self->{'logfh'});
my $fh = $self->{'logfh'};
open($fh, '>>', "$file") || die 'Could not open logfile for appending: '.$!;
select $fh; $| = 1;
$self->{'logfh'} = $fh;
return 1;
}
1;