line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Log::Log4perl::Appender::File::FixedSize; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
28629
|
use 5.006; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
88
|
|
4
|
2
|
|
|
2
|
|
15
|
use strict; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
105
|
|
5
|
2
|
|
|
2
|
|
12
|
use warnings; |
|
2
|
|
|
|
|
10
|
|
|
2
|
|
|
|
|
70
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
1232
|
use File::RoundRobin; |
|
2
|
|
|
|
|
3573
|
|
|
2
|
|
|
|
|
454
|
|
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
|
|
|
|
|
|
|
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 |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head2 new |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=cut |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub new { |
64
|
1
|
|
|
1
|
1
|
28
|
my $class = shift; |
65
|
1
|
|
|
|
|
5
|
my %params = @_; |
66
|
|
|
|
|
|
|
|
67
|
1
|
50
|
|
|
|
5
|
$class = ref($class) if ref($class); |
68
|
|
|
|
|
|
|
|
69
|
1
|
|
50
|
|
|
15
|
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
|
|
|
|
|
|
|
), |
76
|
|
|
|
|
|
|
}; |
77
|
|
|
|
|
|
|
|
78
|
1
|
|
|
|
|
300
|
bless $self, $class; |
79
|
|
|
|
|
|
|
|
80
|
1
|
|
|
|
|
6
|
return $self; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head2 log |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=cut |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub log { |
88
|
5
|
|
|
5
|
1
|
5513
|
my ($self,%params) = @_; |
89
|
|
|
|
|
|
|
|
90
|
5
|
|
|
|
|
27
|
$self->{__file__}->write($params{message}); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 AUTHOR |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
Gligan Calin Horea, C<< >> |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 BUGS |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
100
|
|
|
|
|
|
|
the web interface at L. 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 |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
L |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=item * CPAN Ratings |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
L |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=item * Search CPAN |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
L |
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
|
|
|
|
|
|
|
1; # End of Log::Log4perl::Appender::File::FixedSize |