| 1 | package Log::Log4perl::Appender::File::FixedSize; | ||||||||||||
| 2 | |||||||||||||
| 3 | 3 | ▶ | use 5.006; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 3 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | |||||||||||||
| 7 | 3 | ▶ | use File::RoundRobin; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | |||||||||||||
| 9 | =head1 NAME | ||||||||||||
| 10 | |||||||||||||
| 11 | Log::Log4perl::Appender::File::FixedSize - Log::Log4perl appender which creates files limited in size | ||||||||||||
| 12 | |||||||||||||
| 13 | =head1 VERSION | ||||||||||||
| 14 | |||||||||||||
| 15 | Version 0.01 | ||||||||||||
| 16 | |||||||||||||
| 17 | =cut | ||||||||||||
| 18 | |||||||||||||
| 19 | 3 | our $VERSION = '0.01'; | |||||||||||
| 20 | |||||||||||||
| 21 | |||||||||||||
| 22 | =head1 SYNOPSIS | ||||||||||||
| 23 | |||||||||||||
| 24 | This module allows you to create log files with a limited size. Once the file | ||||||||||||
| 25 | reaches the size limit it starts to overwrite the old content with the new one | ||||||||||||
| 26 | in the same order it was added. | ||||||||||||
| 27 | |||||||||||||
| 28 | Example: | ||||||||||||
| 29 | |||||||||||||
| 30 | use Log::Log4perl::Appender::File::FixedSize; | ||||||||||||
| 31 | |||||||||||||
| 32 | my $file = Log::Log4perl::Appender::File::FixedSize->new( | ||||||||||||
| 33 | filename => '/tmp/log.txt', | ||||||||||||
| 34 | size => '10Mb', | ||||||||||||
| 35 | ); | ||||||||||||
| 36 | ... | ||||||||||||
| 37 | |||||||||||||
| 38 | $file->log(message => 'Hello world'); | ||||||||||||
| 39 | |||||||||||||
| 40 | =head1 Log::Log4perl config | ||||||||||||
| 41 | |||||||||||||
| 42 | Here is an example how you can use this module with Log::Log4perl | ||||||||||||
| 43 | |||||||||||||
| 44 | log4perl.rootLogger=DEBUG, test | ||||||||||||
| 45 | |||||||||||||
| 46 | log4perl.appender.test=Log::Log4perl::Appender::File::FixedSize | ||||||||||||
| 47 | log4perl.appender.test.filename=test.log | ||||||||||||
| 48 | log4perl.appender.test.mode=append | ||||||||||||
| 49 | log4perl.appender.test.size=1M | ||||||||||||
| 50 | |||||||||||||
| 51 | log4perl.appender.test.layout=PatternLayout | ||||||||||||
| 52 | log4perl.appender.test.layout.ConversionPattern=[%r] %F %L %c - %m%n | ||||||||||||
| 53 | |||||||||||||
| 54 | Basically it's the same config as for Log::Log4perl::Appender::File with an extra paramater : I<size> | ||||||||||||
| 55 | |||||||||||||
| 56 | |||||||||||||
| 57 | =head1 SUBROUTINES/METHODS | ||||||||||||
| 58 | |||||||||||||
| 59 | =head2 new | ||||||||||||
| 60 | |||||||||||||
| 61 | =cut | ||||||||||||
| 62 | |||||||||||||
| 63 | 1 | ▶ | sub new { | ||||||||||
|
Subroutine
new: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||
| 64 | 1 | my $class = shift; | |||||||||||
| 65 | 1 | my %params = @_; | |||||||||||
| 66 | |||||||||||||
| 67 | 1 | ▶ | $class = ref($class) if ref($class); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 68 | |||||||||||||
| 69 | my $self = { | ||||||||||||
| 70 | __file__ => File::RoundRobin->new( | ||||||||||||
| 71 | path => $params{filename}, | ||||||||||||
| 72 | size => $params{size}, | ||||||||||||
| 73 | mode => $params{mode} || "new", | ||||||||||||
| 74 | autoflush => $params{autoflush} | ||||||||||||
| 75 | 1 | ▶ | ), | ||||||||||
|
Condition50%1/2
$params{'mode'} || 'new'
MC/DC0%0/1
$params{'mode'} || 'new'
$params{'mode'}
Truth table50%1/2
A
A= $params{'mode'}
| |||||||||||||
| 76 | }; | ||||||||||||
| 77 | |||||||||||||
| 78 | 1 | bless $self, $class; | |||||||||||
| 79 | |||||||||||||
| 80 | 1 | return $self; | |||||||||||
| 81 | } | ||||||||||||
| 82 | |||||||||||||
| 83 | =head2 log | ||||||||||||
| 84 | |||||||||||||
| 85 | =cut | ||||||||||||
| 86 | |||||||||||||
| 87 | 5 | ▶ | sub log { | ||||||||||
|
Subroutine
log: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 88 | 5 | my ($self,%params) = @_; | |||||||||||
| 89 | |||||||||||||
| 90 | 5 | $self->{__file__}->write($params{message}); | |||||||||||
| 91 | } | ||||||||||||
| 92 | |||||||||||||
| 93 | =head1 AUTHOR | ||||||||||||
| 94 | |||||||||||||
| 95 | Gligan Calin Horea, C<< <gliganh at gmail.com> >> | ||||||||||||
| 96 | |||||||||||||
| 97 | =head1 BUGS | ||||||||||||
| 98 | |||||||||||||
| 99 | Please report any bugs or feature requests to C<bug-log-log4perl-appender-file-fixedsize at rt.cpan.org>, or through | ||||||||||||
| 100 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Log-Log4perl-Appender-File-FixedSize>. I will be notified, and then you'll | ||||||||||||
| 101 | automatically be notified of progress on your bug as I make changes. | ||||||||||||
| 102 | |||||||||||||
| 103 | |||||||||||||
| 104 | =head1 SUPPORT | ||||||||||||
| 105 | |||||||||||||
| 106 | You can find documentation for this module with the perldoc command. | ||||||||||||
| 107 | |||||||||||||
| 108 | perldoc Log::Log4perl::Appender::File::FixedSize | ||||||||||||
| 109 | |||||||||||||
| 110 | |||||||||||||
| 111 | You can also look for information at: | ||||||||||||
| 112 | |||||||||||||
| 113 | =over 4 | ||||||||||||
| 114 | |||||||||||||
| 115 | =item * RT: CPAN's request tracker (report bugs here) | ||||||||||||
| 116 | |||||||||||||
| 117 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Log-Log4perl-Appender-File-FixedSize> | ||||||||||||
| 118 | |||||||||||||
| 119 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||||
| 120 | |||||||||||||
| 121 | L<http://annocpan.org/dist/Log-Log4perl-Appender-File-FixedSize> | ||||||||||||
| 122 | |||||||||||||
| 123 | =item * CPAN Ratings | ||||||||||||
| 124 | |||||||||||||
| 125 | L<http://cpanratings.perl.org/d/Log-Log4perl-Appender-File-FixedSize> | ||||||||||||
| 126 | |||||||||||||
| 127 | =item * Search CPAN | ||||||||||||
| 128 | |||||||||||||
| 129 | L<http://search.cpan.org/dist/Log-Log4perl-Appender-File-FixedSize/> | ||||||||||||
| 130 | |||||||||||||
| 131 | =back | ||||||||||||
| 132 | |||||||||||||
| 133 | |||||||||||||
| 134 | =head1 ACKNOWLEDGEMENTS | ||||||||||||
| 135 | |||||||||||||
| 136 | |||||||||||||
| 137 | =head1 LICENSE AND COPYRIGHT | ||||||||||||
| 138 | |||||||||||||
| 139 | Copyright 2012 Gligan Calin Horea. | ||||||||||||
| 140 | |||||||||||||
| 141 | This program is free software; you can redistribute it and/or modify it | ||||||||||||
| 142 | under the terms of either: the GNU General Public License as published | ||||||||||||
| 143 | by the Free Software Foundation; or the Artistic License. | ||||||||||||
| 144 | |||||||||||||
| 145 | See http://dev.perl.org/licenses/ for more information. | ||||||||||||
| 146 | |||||||||||||
| 147 | |||||||||||||
| 148 | =cut | ||||||||||||
| 149 | |||||||||||||
| 150 | 3 | 1; # End of Log::Log4perl::Appender::File::FixedSize | |||||||||||