File Coverage

blib/lib/Log/ger/Output/SimpleFile.pm
Criterion Covered Total %
statement 18 18 100.0
branch 6 8 75.0
condition n/a
subroutine 4 4 100.0
pod 0 1 0.0
total 28 31 90.3


line stmt bran cond sub pod time code
1             package Log::ger::Output::SimpleFile;
2              
3             our $DATE = '2019-09-10'; # DATE
4             our $VERSION = '0.002'; # VERSION
5              
6 1     1   1921 use strict;
  1         2  
  1         24  
7 1     1   4 use warnings;
  1         1  
  1         219  
8              
9             sub get_hooks {
10 4     4 0 6755 my %conf = @_;
11              
12 4         6 my $fh;
13 4 100       13 if (defined(my $path = $conf{path})) {
    100          
14 2 50       87 open $fh, ">>", $path or die "Can't open log file '$path': $!";
15             } elsif ($fh = $conf{handle}) {
16             } else {
17 1         10 die "Please specify 'path' or 'handle'";
18             }
19              
20             return {
21             create_log_routine => [
22             __PACKAGE__, 50,
23             sub {
24 9     9   2129 my %args = @_;
25              
26             my $logger = sub {
27 3         2086 print $fh $_[1];
28 3 50       13 print $fh "\n" unless $_[1] =~ /\R\z/;
29 3         106 $fh->flush;
30 9         26 };
31 9         23 [$logger];
32 3         23 }],
33             };
34             }
35              
36             1;
37             # ABSTRACT: Send logs to file
38              
39             __END__