line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Clustericious::Log; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
9724
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
70
|
|
4
|
2
|
|
|
2
|
|
14
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
56
|
|
5
|
2
|
|
|
2
|
|
23
|
use v5.10; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
145
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
BEGIN { |
8
|
2
|
50
|
|
2
|
|
10
|
unless($INC{'File/HomeDir/Test.pm'}) |
9
|
|
|
|
|
|
|
{ |
10
|
2
|
|
|
2
|
|
126
|
eval q{ use File::HomeDir::Test }; |
|
2
|
|
|
|
|
1872
|
|
|
2
|
|
|
|
|
50535
|
|
|
2
|
|
|
|
|
12
|
|
11
|
2
|
50
|
|
|
|
1499
|
die $@ if $@; |
12
|
|
|
|
|
|
|
} |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
2
|
|
|
2
|
|
939
|
use File::HomeDir; |
|
2
|
|
|
|
|
4354
|
|
|
2
|
|
|
|
|
134
|
|
16
|
2
|
|
|
2
|
|
985
|
use Test::Builder::Module; |
|
2
|
|
|
|
|
14268
|
|
|
2
|
|
|
|
|
20
|
|
17
|
2
|
|
|
2
|
|
583
|
use Clustericious::Log (); |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
43
|
|
18
|
2
|
|
|
2
|
|
12
|
use Carp qw( carp ); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1819
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# ABSTRACT: Clustericious logging in tests. |
21
|
|
|
|
|
|
|
our $VERSION = '0.15'; # VERSION |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# TRACE DEBUG INFO WARN ERROR FATAL |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub import |
27
|
|
|
|
|
|
|
{ |
28
|
2
|
|
|
2
|
|
19
|
my($class) = shift; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# first caller wins |
31
|
2
|
|
|
|
|
6
|
state $counter = 0; |
32
|
2
|
50
|
|
|
|
13
|
if($counter++) |
33
|
|
|
|
|
|
|
{ |
34
|
0
|
|
|
|
|
0
|
my $caller = caller; |
35
|
0
|
0
|
|
|
|
0
|
unless($caller eq 'Test::Clustericious::Cluster') |
36
|
|
|
|
|
|
|
{ |
37
|
0
|
|
|
|
|
0
|
my $tb = Test::Builder::Module->builder; |
38
|
0
|
|
|
|
|
0
|
$tb->diag("you must use Test::Clustericious::Log before Test::Clustericious::Cluster"); |
39
|
|
|
|
|
|
|
} |
40
|
0
|
|
|
|
|
0
|
return; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
2
|
|
|
|
|
4
|
$Clustericious::Log::harness_active = 0; |
44
|
|
|
|
|
|
|
|
45
|
2
|
|
|
|
|
12
|
my $home = File::HomeDir->my_home; |
46
|
2
|
50
|
|
|
|
454
|
mkdir "$home/etc" unless -d "$home/etc"; |
47
|
2
|
50
|
|
|
|
160
|
mkdir "$home/log" unless -d "$home/log"; |
48
|
|
|
|
|
|
|
|
49
|
2
|
|
|
|
|
33
|
my $config = { |
50
|
|
|
|
|
|
|
FileX => [ 'TRACE', 'FATAL' ], |
51
|
|
|
|
|
|
|
NoteX => [ 'DEBUG', 'WARN' ], |
52
|
|
|
|
|
|
|
DiagX => [ 'ERROR', 'FATAL' ], |
53
|
|
|
|
|
|
|
}; |
54
|
|
|
|
|
|
|
|
55
|
2
|
|
|
|
|
4
|
my $args; |
56
|
2
|
50
|
|
|
|
8
|
if(@_ == 1) |
57
|
|
|
|
|
|
|
{ |
58
|
0
|
|
|
|
|
0
|
die; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
else |
61
|
|
|
|
|
|
|
{ |
62
|
2
|
|
|
|
|
5
|
$args = { @_ }; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
2
|
|
|
|
|
5
|
foreach my $type (qw( file note diag )) |
66
|
|
|
|
|
|
|
{ |
67
|
6
|
50
|
|
|
|
18
|
if(defined $args->{$type}) |
68
|
|
|
|
|
|
|
{ |
69
|
0
|
|
|
|
|
0
|
my $name = ucfirst($type) . 'X'; |
70
|
0
|
0
|
|
|
|
0
|
if($args->{$type} =~ /^(TRACE|DEBUG|INFO|WARN|ERROR|FATAL)(..(TRACE|DEBUG|INFO|WARN|ERROR|FATAL))$/) |
|
|
0
|
|
|
|
|
|
71
|
|
|
|
|
|
|
{ |
72
|
0
|
|
|
|
|
0
|
my($min,$max) = ($1,$3); |
73
|
0
|
0
|
|
|
|
0
|
$max = $min unless $max; |
74
|
0
|
|
|
|
|
0
|
$config->{$name} = [ $min, $max ]; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
elsif($args->{$type} eq 'NONE') |
77
|
|
|
|
|
|
|
{ |
78
|
0
|
|
|
|
|
0
|
delete $config->{$name}; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
else |
81
|
|
|
|
|
|
|
{ |
82
|
0
|
|
|
|
|
0
|
carp "illegal log range: " . $args->{$type}; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
2
|
|
|
|
|
153
|
open my $fh, '>', "$home/etc/log4perl.conf"; |
88
|
|
|
|
|
|
|
|
89
|
2
|
|
|
|
|
12
|
print $fh "log4perl.rootLogger=TRACE, "; |
90
|
2
|
50
|
|
|
|
13
|
print $fh "FileX, " if defined $config->{FileX}; |
91
|
2
|
50
|
|
|
|
9
|
print $fh "NoteX, " if defined $config->{NoteX}; |
92
|
2
|
50
|
|
|
|
9
|
print $fh "DiagX, " if defined $config->{DiagX}; |
93
|
2
|
|
|
|
|
3
|
print $fh "\n"; |
94
|
|
|
|
|
|
|
|
95
|
2
|
|
|
|
|
12
|
while(my($appender, $levels) = each %$config) |
96
|
|
|
|
|
|
|
{ |
97
|
6
|
|
|
|
|
8
|
my($min, $max) = @{ $levels }; |
|
6
|
|
|
|
|
11
|
|
98
|
6
|
|
|
|
|
12
|
print $fh "log4perl.filter.Match$appender = Log::Log4perl::Filter::LevelRange\n"; |
99
|
6
|
|
|
|
|
12
|
print $fh "log4perl.filter.Match$appender.LevelMin = $min\n"; |
100
|
6
|
|
|
|
|
9
|
print $fh "log4perl.filter.Match$appender.LevelMax = $max\n"; |
101
|
6
|
|
|
|
|
24
|
print $fh "log4perl.filter.Match$appender.AcceptOnMatch = true\n"; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
2
|
|
|
|
|
5
|
print $fh "log4perl.appender.FileX=Log::Log4perl::Appender::File\n"; |
105
|
2
|
|
|
|
|
6
|
print $fh "log4perl.appender.FileX.filename=$home/log/test.log\n"; |
106
|
2
|
|
|
|
|
4
|
print $fh "log4perl.appender.FileX.mode=append\n"; |
107
|
2
|
|
|
|
|
2
|
print $fh "log4perl.appender.FileX.layout=PatternLayout\n"; |
108
|
2
|
|
|
|
|
3
|
print $fh "log4perl.appender.FileX.layout.ConversionPattern=[%P %p{1} %rms] %F:%L %m%n\n"; |
109
|
2
|
|
|
|
|
3
|
print $fh "log4perl.appender.FileX.Filter=MatchFileX\n"; |
110
|
|
|
|
|
|
|
|
111
|
2
|
|
|
|
|
3
|
print $fh "log4perl.appender.NoteX=Log::Log4perl::Appender::TAP\n"; |
112
|
2
|
|
|
|
|
3
|
print $fh "log4perl.appender.NoteX.method=note\n"; |
113
|
2
|
|
|
|
|
2
|
print $fh "log4perl.appender.NoteX.layout=PatternLayout\n"; |
114
|
2
|
|
|
|
|
25
|
print $fh "log4perl.appender.NoteX.layout.ConversionPattern=%5p %m%n\n"; |
115
|
2
|
|
|
|
|
4
|
print $fh "log4perl.appender.NoteX.Filter=MatchNoteX\n"; |
116
|
|
|
|
|
|
|
|
117
|
2
|
|
|
|
|
2
|
print $fh "log4perl.appender.DiagX=Log::Log4perl::Appender::TAP\n"; |
118
|
2
|
|
|
|
|
3
|
print $fh "log4perl.appender.DiagX.method=diag\n"; |
119
|
2
|
|
|
|
|
4
|
print $fh "log4perl.appender.DiagX.layout=PatternLayout\n"; |
120
|
2
|
|
|
|
|
3
|
print $fh "log4perl.appender.DiagX.layout.ConversionPattern=%5p %m%n\n"; |
121
|
2
|
|
|
|
|
4
|
print $fh "log4perl.appender.DiagX.Filter=MatchDiagX\n"; |
122
|
|
|
|
|
|
|
|
123
|
2
|
|
|
|
|
145
|
close $fh; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
END |
127
|
|
|
|
|
|
|
{ |
128
|
1
|
|
|
1
|
|
5614
|
my $tb = Test::Builder::Module->builder; |
129
|
1
|
|
|
|
|
21
|
my $home = File::HomeDir->my_home; |
130
|
|
|
|
|
|
|
|
131
|
1
|
50
|
|
|
|
67
|
unless($tb->is_passing) |
132
|
|
|
|
|
|
|
{ |
133
|
0
|
0
|
|
|
|
|
if(-r "$home/log/test.log") |
134
|
|
|
|
|
|
|
{ |
135
|
0
|
|
|
|
|
|
$tb->diag("detailed log"); |
136
|
0
|
|
|
|
|
|
open my $fh, '<', "$home/log/test.log"; |
137
|
0
|
|
|
|
|
|
$tb->diag(<$fh>); |
138
|
0
|
|
|
|
|
|
close $fh; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
else |
141
|
|
|
|
|
|
|
{ |
142
|
0
|
|
|
|
|
|
$tb->diag("no detailed log"); |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
1; |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
__END__ |