line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FusionInventory::Agent::Logger::File; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
23794739
|
use strict; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
70
|
|
4
|
2
|
|
|
2
|
|
7
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
90
|
|
5
|
2
|
|
|
2
|
|
6
|
use base 'FusionInventory::Agent::Logger::Backend'; |
|
2
|
|
|
|
|
40
|
|
|
2
|
|
|
|
|
550
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
12
|
use English qw(-no_match_vars); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
27
|
|
8
|
2
|
|
|
2
|
|
884
|
use Fcntl qw(:flock); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
242
|
|
9
|
2
|
|
|
2
|
|
502
|
use File::stat; |
|
2
|
|
|
|
|
5257
|
|
|
2
|
|
|
|
|
12
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new { |
12
|
5
|
|
|
5
|
1
|
11
|
my ($class, %params) = @_; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my $self = { |
15
|
|
|
|
|
|
|
logfile => $params{config}->{logfile}, |
16
|
|
|
|
|
|
|
logfile_maxsize => $params{config}->{'logfile-maxsize'} ? |
17
|
5
|
100
|
|
|
|
21
|
$params{config}->{'logfile-maxsize'} * 1024 * 1024 : 0 |
18
|
|
|
|
|
|
|
}; |
19
|
5
|
|
|
|
|
6
|
bless $self, $class; |
20
|
|
|
|
|
|
|
|
21
|
5
|
|
|
|
|
36
|
return $self; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub addMessage { |
25
|
2053
|
|
|
2053
|
1
|
2370
|
my ($self, %params) = @_; |
26
|
|
|
|
|
|
|
|
27
|
2053
|
|
|
|
|
1515
|
my $level = $params{level}; |
28
|
2053
|
|
|
|
|
1369
|
my $message = $params{message}; |
29
|
|
|
|
|
|
|
|
30
|
2053
|
|
|
|
|
1231
|
my $handle; |
31
|
2053
|
100
|
|
|
|
2593
|
if ($self->{logfile_maxsize}) { |
32
|
1024
|
|
|
|
|
1562
|
my $stat = stat($self->{logfile}); |
33
|
1024
|
100
|
100
|
|
|
83925
|
if ($stat && $stat->size() > $self->{logfile_maxsize}) { |
34
|
1
|
50
|
|
|
|
668
|
if (!open $handle, '>', $self->{logfile}) { |
35
|
0
|
|
|
|
|
0
|
warn "Can't open $self->{logfile}: $ERRNO"; |
36
|
0
|
|
|
|
|
0
|
return; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
2053
|
50
|
66
|
|
|
45286
|
if (!$handle && !open $handle, '>>', $self->{logfile}) { |
42
|
0
|
|
|
|
|
0
|
warn "can't open $self->{logfile}: $ERRNO"; |
43
|
0
|
|
|
|
|
0
|
return; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
2053
|
|
|
|
|
1488
|
my $locked; |
47
|
2053
|
|
|
|
|
1973
|
my $retryTill = time + 60; |
48
|
|
|
|
|
|
|
|
49
|
2053
|
|
66
|
|
|
6058
|
while ($retryTill > time && !$locked) { |
50
|
|
|
|
|
|
|
## no critic (ProhibitBitwise) |
51
|
|
|
|
|
|
|
# get an exclusive lock on log file |
52
|
2053
|
50
|
|
|
|
9705
|
$locked = 1 if flock($handle, LOCK_EX|LOCK_NB); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
2053
|
50
|
|
|
|
2456
|
if (!$locked) { |
56
|
0
|
|
|
|
|
0
|
die "can't get an exclusive lock on $self->{logfile}: $ERRNO"; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
2053
|
|
|
|
|
1410
|
print {$handle} |
|
2053
|
|
|
|
|
24663
|
|
60
|
|
|
|
|
|
|
"[". localtime() ."]" . |
61
|
|
|
|
|
|
|
"[$level]" . |
62
|
|
|
|
|
|
|
" $message\n"; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# closing handle release the lock automatically |
65
|
2053
|
|
|
|
|
37744
|
close $handle; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
1; |
70
|
|
|
|
|
|
|
__END__ |