File Coverage

blib/lib/Log/ger/Output/SimpleFile.pm
Criterion Covered Total %
statement 19 19 100.0
branch 6 8 75.0
condition n/a
subroutine 5 5 100.0
pod 0 2 0.0
total 30 34 88.2


line stmt bran cond sub pod time code
1             package Log::ger::Output::SimpleFile;
2              
3             our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
4             our $DATE = '2020-03-11'; # DATE
5             our $DIST = 'Log-ger-Output-SimpleFile'; # DIST
6             our $VERSION = '0.004'; # VERSION
7              
8 1     1   1814 use strict;
  1         1  
  1         26  
9 1     1   4 use warnings;
  1         1  
  1         236  
10              
11             sub meta { +{
12 4     4 0 6892 v => 2,
13             } }
14              
15             sub get_hooks {
16 4     4 0 44 my %plugin_conf = @_;
17              
18 4         7 my $fh;
19 4 100       12 if (defined(my $path = $plugin_conf{path})) {
    100          
20 2 50       93 open $fh, ">>", $path or die "Can't open log file '$path': $!";
21             } elsif ($fh = $plugin_conf{handle}) {
22             } else {
23 1         11 die "Please specify 'path' or 'handle'";
24             }
25              
26             return {
27             create_outputter => [
28             __PACKAGE__, # key
29             50, # priority
30             sub { # hook
31 9     9   1469 my %hook_args = @_; # see Log::ger::Manual::Internals/"Arguments passed to hook"
32              
33             my $outputter = sub {
34 3         2617 my ($per_target_conf, $fmsg, $per_msg_conf) = @_;
35 3 50       22 print $fh $fmsg . ($fmsg =~ /\R\z/ ? "" : "\n");
36 3         86 $fh->flush;
37 9         28 };
38 9         21 [$outputter];
39 3         24 }],
40             };
41             }
42              
43             1;
44             # ABSTRACT: Send logs to file
45              
46             __END__