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