line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Poet::t::Log; |
2
|
|
|
|
|
|
|
$Poet::t::Log::VERSION = '0.16'; |
3
|
1
|
|
|
1
|
|
704
|
use Poet::Tools qw(rmtree tempdir_simple); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
use JSON::XS; |
5
|
|
|
|
|
|
|
use Test::Class::Most parent => 'Poet::Test::Class'; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
__PACKAGE__->initialize_temp_env(); |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub test_log_config : Tests { |
10
|
|
|
|
|
|
|
my $poet = Poet::Environment->current_env; |
11
|
|
|
|
|
|
|
my $conf = $poet->conf; |
12
|
|
|
|
|
|
|
my $logs_dir = $poet->logs_dir; |
13
|
|
|
|
|
|
|
my $temp_dir = tempdir_simple(); |
14
|
|
|
|
|
|
|
my $other_dir = "$temp_dir/other"; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my $test = sub { |
17
|
|
|
|
|
|
|
my ( $conf_settings, $expected ) = @_; |
18
|
|
|
|
|
|
|
my $lex = $conf->set_local($conf_settings); |
19
|
|
|
|
|
|
|
my $log_conf = Poet::Log->generate_log4perl_config(); |
20
|
|
|
|
|
|
|
is( $log_conf, $expected, encode_json($conf_settings) ); |
21
|
|
|
|
|
|
|
}; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my $default_layout = "%d{dd/MMM/yyyy:HH:mm:ss.SS} [%p] %c - %m - %F:%L - %P%n"; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
rmtree($_) for ( $logs_dir, $other_dir ); |
26
|
|
|
|
|
|
|
$test->( |
27
|
|
|
|
|
|
|
{}, |
28
|
|
|
|
|
|
|
"log4perl.logger = INFO, default |
29
|
|
|
|
|
|
|
log4perl.appender.default = Log::Log4perl::Appender::File |
30
|
|
|
|
|
|
|
log4perl.appender.default.layout = Log::Log4perl::Layout::PatternLayout |
31
|
|
|
|
|
|
|
log4perl.appender.default.layout.ConversionPattern = $default_layout |
32
|
|
|
|
|
|
|
log4perl.appender.default.filename = $logs_dir/poet.log |
33
|
|
|
|
|
|
|
" |
34
|
|
|
|
|
|
|
); |
35
|
|
|
|
|
|
|
ok( -d $logs_dir, "$logs_dir created" ); |
36
|
|
|
|
|
|
|
ok( !-d $other_dir, "$other_dir not created" ); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
rmtree($_) for ( $logs_dir, $other_dir ); |
39
|
|
|
|
|
|
|
$test->( |
40
|
|
|
|
|
|
|
{ log => { 'defaults' => { level => 'debug', output => 'foo.log' } } }, |
41
|
|
|
|
|
|
|
"log4perl.logger = DEBUG, default |
42
|
|
|
|
|
|
|
log4perl.appender.default = Log::Log4perl::Appender::File |
43
|
|
|
|
|
|
|
log4perl.appender.default.layout = Log::Log4perl::Layout::PatternLayout |
44
|
|
|
|
|
|
|
log4perl.appender.default.layout.ConversionPattern = $default_layout |
45
|
|
|
|
|
|
|
log4perl.appender.default.filename = $logs_dir/foo.log |
46
|
|
|
|
|
|
|
" |
47
|
|
|
|
|
|
|
); |
48
|
|
|
|
|
|
|
ok( -d $logs_dir, "$logs_dir created" ); |
49
|
|
|
|
|
|
|
ok( !-d $other_dir, "$other_dir not created" ); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
$test->( |
52
|
|
|
|
|
|
|
{ |
53
|
|
|
|
|
|
|
log => { |
54
|
|
|
|
|
|
|
'defaults' => { level => 'info', output => 'foo.log' }, |
55
|
|
|
|
|
|
|
'class' => { |
56
|
|
|
|
|
|
|
'Bar' => { level => 'warn', output => "$other_dir/bar.log" }, |
57
|
|
|
|
|
|
|
'Bar.Errors' => { output => 'stderr' }, |
58
|
|
|
|
|
|
|
'Bar.NonErrors' => { output => 'stdout' }, |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
}, |
62
|
|
|
|
|
|
|
"log4perl.logger = INFO, default |
63
|
|
|
|
|
|
|
log4perl.appender.default = Log::Log4perl::Appender::File |
64
|
|
|
|
|
|
|
log4perl.appender.default.layout = Log::Log4perl::Layout::PatternLayout |
65
|
|
|
|
|
|
|
log4perl.appender.default.layout.ConversionPattern = $default_layout |
66
|
|
|
|
|
|
|
log4perl.appender.default.filename = $logs_dir/foo.log |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
log4perl.logger.Bar = WARN, Bar |
69
|
|
|
|
|
|
|
log4perl.appender.Bar = Log::Log4perl::Appender::File |
70
|
|
|
|
|
|
|
log4perl.appender.Bar.layout = Log::Log4perl::Layout::PatternLayout |
71
|
|
|
|
|
|
|
log4perl.appender.Bar.layout.ConversionPattern = $default_layout |
72
|
|
|
|
|
|
|
log4perl.appender.Bar.filename = $other_dir/bar.log |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
log4perl.logger.Bar.Errors = INFO, Bar_Errors |
75
|
|
|
|
|
|
|
log4perl.appender.Bar_Errors = Log::Log4perl::Appender::Screen |
76
|
|
|
|
|
|
|
log4perl.appender.Bar_Errors.layout = Log::Log4perl::Layout::PatternLayout |
77
|
|
|
|
|
|
|
log4perl.appender.Bar_Errors.layout.ConversionPattern = $default_layout |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
log4perl.logger.Bar.NonErrors = INFO, Bar_NonErrors |
80
|
|
|
|
|
|
|
log4perl.appender.Bar_NonErrors = Log::Log4perl::Appender::Screen |
81
|
|
|
|
|
|
|
log4perl.appender.Bar_NonErrors.layout = Log::Log4perl::Layout::PatternLayout |
82
|
|
|
|
|
|
|
log4perl.appender.Bar_NonErrors.layout.ConversionPattern = $default_layout |
83
|
|
|
|
|
|
|
log4perl.appender.Bar_NonErrors.stderr = 0 |
84
|
|
|
|
|
|
|
" |
85
|
|
|
|
|
|
|
); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
1; |