Log-Mini/lib/Log/Mini/LoggerFILE.pm

40 lines
551 B
Perl
Raw Normal View History

2019-02-21 22:30:49 +03:00
package Log::Mini::LoggerFILE;
use strict;
use warnings;
use IO::Handle;
2019-03-19 14:57:41 +03:00
2019-02-21 22:30:49 +03:00
use base 'Log::Mini::LoggerBase';
sub new {
my $self = shift->SUPER::new(@_);
my (%params) = @_;
$self->{file} = $params{file};
2019-03-20 15:39:51 +03:00
# TODO: Allow logrotate
2019-02-21 22:30:49 +03:00
open my $fh, '>>', $params{file} or die $!;
if (defined $params{'synced'}) {
2019-03-19 14:57:41 +03:00
$fh->autoflush(1);
2019-02-21 22:30:49 +03:00
}
$self->{fh} = $fh;
return $self;
}
sub _print {
my $self = shift;
my $fh = $self->{fh};
2019-03-19 14:57:41 +03:00
print $fh @_;
2019-02-21 22:30:49 +03:00
}
sub DESTROY {
close shift->{'fh'};
return;
}
1;