All the files
This commit is contained in:
35
lib/logger.pm
Normal file
35
lib/logger.pm
Normal 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;
|
||||
Reference in New Issue
Block a user