line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Log::Any::Adapter::Fille; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# Advanced adapter for logging to files |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
23161
|
use 5.008001; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
33
|
|
8
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
41
|
|
9
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
29
|
|
10
|
1
|
|
|
1
|
|
497
|
use utf8::all; |
|
1
|
|
|
|
|
46255
|
|
|
1
|
|
|
|
|
7
|
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
2956
|
use Config; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
45
|
|
13
|
1
|
|
|
1
|
|
4
|
use Fcntl qw(:flock); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
150
|
|
14
|
1
|
|
|
1
|
|
602
|
use POSIX; |
|
1
|
|
|
|
|
5623
|
|
|
1
|
|
|
|
|
9
|
|
15
|
1
|
|
|
1
|
|
6403
|
use IO::File; |
|
1
|
|
|
|
|
6170
|
|
|
1
|
|
|
|
|
437
|
|
16
|
1
|
|
|
1
|
|
590
|
use Time::HiRes qw(gettimeofday); |
|
1
|
|
|
|
|
1339
|
|
|
1
|
|
|
|
|
5
|
|
17
|
1
|
|
|
1
|
|
1857
|
use Log::Any::Adapter::Util (); |
|
1
|
|
|
|
|
14865
|
|
|
1
|
|
|
|
|
28
|
|
18
|
|
|
|
|
|
|
|
19
|
1
|
|
|
1
|
|
8
|
use base qw/Log::Any::Adapter::Base/; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
589
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
#--- |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# Log levels (names satisfy the official log names Log::Any) |
26
|
|
|
|
|
|
|
my %levels = ( |
27
|
|
|
|
|
|
|
0 => 'EMERGENCY', |
28
|
|
|
|
|
|
|
1 => 'ALERT', |
29
|
|
|
|
|
|
|
2 => 'CRITICAL', |
30
|
|
|
|
|
|
|
3 => 'ERROR', |
31
|
|
|
|
|
|
|
4 => 'WARNING', |
32
|
|
|
|
|
|
|
5 => 'NOTICE', |
33
|
|
|
|
|
|
|
6 => 'INFO', |
34
|
|
|
|
|
|
|
7 => 'DEBUG', |
35
|
|
|
|
|
|
|
8 => 'TRACE', |
36
|
|
|
|
|
|
|
); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
my $HAS_FLOCK = $Config{d_flock} || $Config{d_fcntl_can_lock} || $Config{d_lockf}; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub new { |
41
|
0
|
|
|
0
|
|
|
my ( $class, @args ) = @_; |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
return $class->SUPER::new(@args); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub init { |
47
|
0
|
|
|
0
|
|
|
my $self = shift; |
48
|
|
|
|
|
|
|
|
49
|
0
|
0
|
|
|
|
|
if ( exists $self->{log_level} ) { |
50
|
0
|
0
|
|
|
|
|
$self->{log_level} = Log::Any::Adapter::Util::numeric_level( $self->{log_level} ) |
51
|
|
|
|
|
|
|
unless $self->{log_level} =~ /^\d+$/; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
else { |
54
|
0
|
|
|
|
|
|
$self->{log_level} = Log::Any::Adapter::Util::numeric_level('info'); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
0
|
0
|
|
|
|
|
open( $self->{fh}, ">>", $self->{file} ) or die "Не удалось открыть файл '$self->{file}': $!"; |
58
|
0
|
|
|
|
|
|
$self->{fh}->autoflush(1); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
foreach my $method ( Log::Any::Adapter::Util::logging_methods() ) { |
62
|
1
|
|
|
1
|
|
4840
|
no strict 'refs'; ## no critic (ProhibitNoStrict) |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
427
|
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
my $method_level = Log::Any::Adapter::Util::numeric_level($method); |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
*{$method} = sub { |
67
|
|
|
|
|
|
|
my ( $self, $text ) = @_; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
return if $method_level > $self->{log_level}; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
my ( $sec, $msec ) = gettimeofday; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# Log line in "date time pid level message" format |
74
|
|
|
|
|
|
|
my $msg = sprintf( "%s.%.6d %5d %s %s\n", strftime( "%Y-%m-%d %H:%M:%S", localtime($sec) ), $msec, $$, $levels{$method_level}, $text ); |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
flock( $self->{fh}, LOCK_EX ) if $HAS_FLOCK; |
77
|
|
|
|
|
|
|
$self->{fh}->print($msg); |
78
|
|
|
|
|
|
|
flock( $self->{fh}, LOCK_UN ) if $HAS_FLOCK; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
foreach my $method ( Log::Any::Adapter::Util::detection_methods() ) { |
83
|
1
|
|
|
1
|
|
8
|
no strict 'refs'; ## no critic (ProhibitNoStrict) |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
217
|
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
my $base = substr( $method, 3 ); |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
my $method_level = Log::Any::Adapter::Util::numeric_level($base); |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
*{$method} = sub { |
90
|
|
|
|
|
|
|
return !!( $method_level <= $_[0]->{log_level} ); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
1; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
__END__ |