File Coverage

blib/lib/Log/Log4perl/JavaMap/RollingFileAppender.pm
Criterion Covered Total %
statement 25 38 65.7
branch 4 22 18.1
condition 0 14 0.0
subroutine 4 4 100.0
pod 0 1 0.0
total 33 79 41.7


line stmt bran cond sub pod time code
1              
2             use Carp;
3 1     1   10 use strict;
  1         2  
  1         93  
4 1     1   11 use Log::Dispatch::FileRotate 1.10;
  1         2  
  1         36  
5 1     1   6  
  1         18  
  1         514  
6              
7             my ($class, $appender_name, $data) = @_;
8             my $stderr;
9 1     1 0 3  
10 1         2 my $filename = $data->{File}{value} ||
11             $data->{filename}{value} ||
12             die "'File' not supplied for appender '$appender_name', required for a '$data->{value}'\n";
13              
14 1   0     7 my $mode;
15             if (defined($data->{Append}{value})){
16 1         2 if (lc $data->{Append}{value} eq 'true' || $data->{Append}{value} == 1){
17 1 50       9 $mode = 'append';
18 0 0 0     0 }elsif (lc $data->{Append}{value} eq 'false' || $data->{Append}{value} == 0) {
    0 0        
    0          
19 0         0 $mode = 'write';
20             }elsif($data->{Append} =~ /^(write|append)$/){
21 0         0 $mode = $data->{Append}
22             }else{
23             die "'$data->{Append}' is not a legal value for Append for appender '$appender_name', '$data->{value}'\n";
24 0         0 }
25 0         0 }else{
26             $mode = 'append';
27             }
28 1         5  
29             my $autoflush;
30             if (defined($data->{BufferedIO}{value})){
31 1         3 if (lc $data->{BufferedIO}{value} eq 'true' || $data->{BufferedIO}{value}){
32 1 50       3 $autoflush = 1;
33 0 0 0     0 }elsif (lc $data->{BufferedIO}{value} eq 'true' || ! $data->{BufferedIO}{value}) {
    0 0        
34 0         0 $autoflush = 0;
35             }else{
36 0         0 die "'$data->{BufferedIO}' is not a legal value for BufferedIO for appender '$appender_name', '$data->{value}'\n";
37             }
38 0         0 }else{
39             $autoflush = 1;
40             }
41 1         2  
42             my $max;
43             if (defined $data->{MaxBackupIndex}{value}) {
44 1         3 $max = $data->{MaxBackupIndex}{value};
45 1 50       3 }elsif (defined $data->{max}{value}){
    0          
46 1         5 $max = $data->{max}{value};
47             }else{
48 0         0 $max = 1;
49              
50 0         0 }
51              
52             my $size;
53             if (defined $data->{MaxFileSize}{value}) {
54 1         2 $size = $data->{MaxFileSize}{value}
55 1 50       102 }elsif (defined $data->{size}{value}){
    0          
56             $size = $data->{size}{value};
57 1         3 }else{
58 0         0 $size = 10_000_000;
59             }
60 0         0  
61              
62             return Log::Log4perl::Appender->new("Log::Dispatch::FileRotate",
63             name => $appender_name,
64 1         89 filename => $filename,
65             mode => $mode,
66             autoflush => $autoflush,
67             size => $size,
68             max => $max,
69             );
70             }
71              
72             1;
73              
74             =encoding utf8
75              
76             =head1 NAME
77              
78             Log::Log4perl::JavaMap::RollingFileAppender - wraps Log::Dispatch::FileRotate
79              
80             =head1 SYNOPSIS
81              
82              
83             =head1 DESCRIPTION
84              
85             This maps log4j's RollingFileAppender to Log::Dispatch::FileRotate
86             by Mark Pfeiffer, <markpf@mlp-consulting.com.au>.
87              
88             Possible config properties for log4j ConsoleAppender are
89              
90             File
91             Append "true|false|1|0" default=true
92             BufferedIO "true|false|1|0" default=false (i.e. autoflush is on)
93             MaxFileSize default 10_000_000
94             MaxBackupIndex default is 1
95              
96             Possible config properties for Log::Dispatch::FileRotate are
97              
98             filename
99             mode "write|append"
100             autoflush 0|1
101             size
102             max
103              
104             =head1 SEE ALSO
105              
106             http://jakarta.apache.org/log4j/docs/
107              
108             Log::Log4perl::Javamap
109              
110             =head1 LICENSE
111              
112             Copyright 2002-2013 by Mike Schilli E<lt>m@perlmeister.comE<gt>
113             and Kevin Goess E<lt>cpan@goess.orgE<gt>.
114              
115             This library is free software; you can redistribute it and/or modify
116             it under the same terms as Perl itself.
117              
118             =head1 AUTHOR
119              
120             Please contribute patches to the project on Github:
121              
122             http://github.com/mschilli/log4perl
123              
124             Send bug reports or requests for enhancements to the authors via our
125              
126             MAILING LIST (questions, bug reports, suggestions/patches):
127             log4perl-devel@lists.sourceforge.net
128              
129             Authors (please contact them via the list above, not directly):
130             Mike Schilli <m@perlmeister.com>,
131             Kevin Goess <cpan@goess.org>
132              
133             Contributors (in alphabetical order):
134             Ateeq Altaf, Cory Bennett, Jens Berthold, Jeremy Bopp, Hutton
135             Davidson, Chris R. Donnelly, Matisse Enzer, Hugh Esco, Anthony
136             Foiani, James FitzGibbon, Carl Franks, Dennis Gregorovic, Andy
137             Grundman, Paul Harrington, Alexander Hartmaier David Hull,
138             Robert Jacobson, Jason Kohles, Jeff Macdonald, Markus Peter,
139             Brett Rann, Peter Rabbitson, Erik Selberg, Aaron Straup Cope,
140             Lars Thegler, David Viner, Mac Yang.
141