36 lines
719 B
Perl
36 lines
719 B
Perl
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;
|