2023-03-17 18:29:38 +03:00
|
|
|
package Log::Mini::Logger::FILE;
|
2019-02-21 22:30:49 +03:00
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
use IO::Handle;
|
|
|
|
|
2023-03-17 18:29:38 +03:00
|
|
|
use base 'Log::Mini::Logger::Base';
|
2019-03-19 14:57:41 +03:00
|
|
|
|
2023-03-17 18:29:38 +03:00
|
|
|
sub new
|
|
|
|
{
|
2019-02-21 22:30:49 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2023-03-17 18:29:38 +03:00
|
|
|
sub _print
|
|
|
|
{
|
2019-02-21 22:30:49 +03:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2023-03-17 18:29:38 +03:00
|
|
|
sub DESTROY
|
|
|
|
{
|
2019-02-21 22:30:49 +03:00
|
|
|
close shift->{'fh'};
|
|
|
|
return;
|
|
|
|
}
|
2023-03-17 18:29:38 +03:00
|
|
|
|
2019-02-21 22:30:49 +03:00
|
|
|
1;
|