line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Log::Any::Adapter::Dupout; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# Cunning adapter for logging to a duplicate of STDOUT |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
8439
|
use 5.008001; |
|
2
|
|
|
|
|
7
|
|
8
|
2
|
|
|
2
|
|
11
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
41
|
|
9
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
45
|
|
10
|
2
|
|
|
2
|
|
11
|
use utf8::all; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
10
|
|
11
|
|
|
|
|
|
|
|
12
|
2
|
|
|
2
|
|
2703
|
use Carp; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
99
|
|
13
|
2
|
|
|
2
|
|
11
|
use Log::Any::Adapter::Util (); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
41
|
|
14
|
|
|
|
|
|
|
|
15
|
2
|
|
|
2
|
|
8
|
use base qw/Log::Any::Adapter::Base/; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
666
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $VERSION = '0.05'; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub init { |
20
|
1
|
|
|
1
|
0
|
84
|
my ($self) = @_; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# Duplicate STDOUT |
23
|
1
|
50
|
|
|
|
48
|
open( $self->{fh}, '>&', STDOUT ) or croak "Can't dup STDOUT: $!"; ## no critic [InputOutput::RequireBriefOpen] |
24
|
|
|
|
|
|
|
|
25
|
1
|
50
|
|
|
|
6
|
if ( exists $self->{log_level} ) { |
26
|
|
|
|
|
|
|
$self->{log_level} = Log::Any::Adapter::Util::numeric_level( $self->{log_level} ) |
27
|
0
|
0
|
|
|
|
0
|
unless $self->{log_level} =~ /^\d+$/x; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
else { |
30
|
1
|
|
|
|
|
5
|
$self->{log_level} = Log::Any::Adapter::Util::numeric_level('trace'); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
1
|
|
|
|
|
10
|
return; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
foreach my $method ( Log::Any::Adapter::Util::logging_methods() ) { |
37
|
2
|
|
|
2
|
|
15
|
no strict 'refs'; ## no critic (ProhibitNoStrict) |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
382
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
my $method_level = Log::Any::Adapter::Util::numeric_level($method); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
*{$method} = sub { |
42
|
0
|
|
|
0
|
|
|
my ( $self, $text ) = @_; |
43
|
|
|
|
|
|
|
|
44
|
0
|
0
|
|
|
|
|
return if $method_level > $self->{log_level}; |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
$self->{fh}->print("$text\n"); |
47
|
|
|
|
|
|
|
}; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
foreach my $method ( Log::Any::Adapter::Util::detection_methods() ) { |
51
|
2
|
|
|
2
|
|
15
|
no strict 'refs'; ## no critic (ProhibitNoStrict) |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
282
|
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
my $base = substr( $method, 3 ); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
my $method_level = Log::Any::Adapter::Util::numeric_level($base); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
*{$method} = sub { |
58
|
0
|
|
|
0
|
|
|
return !!( $method_level <= $_[0]->{log_level} ); |
59
|
|
|
|
|
|
|
}; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
1; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
__END__ |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=pod |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=encoding UTF-8 |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 NAME |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Log::Any::Adapter::Dupout - Cunning adapter for logging to a duplicate of STDOUT |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 SYNOPSIS |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
use Log::Any::Adapter ('Dupout'); |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# or |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
use Log::Any::Adapter; |
82
|
|
|
|
|
|
|
... |
83
|
|
|
|
|
|
|
Log::Any::Adapter->set('Dupout'); |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
# with minimum level 'warn' |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
use Log::Any::Adapter ('Dupout', log_level => 'warn' ); |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# and later |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
open(STDOUT, ">/dev/null"); |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 DESCRIPTION |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Adapter Dupout are intended to log messages into duplicate of standard |
97
|
|
|
|
|
|
|
descriptor STDOUT. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Logging into a duplicate of standard descriptor might be needed in special |
100
|
|
|
|
|
|
|
occasions when you need to redefine or even close standard descriptor but you |
101
|
|
|
|
|
|
|
want to continue displaying messages wherever they are displayed by a standard |
102
|
|
|
|
|
|
|
descriptor. See more L<Log::Any::Adapter::Dupstd|Log::Any::Adapter::Dupstd>. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
These adapters work similarly to ordinary adapters from distributive Log::Any - |
105
|
|
|
|
|
|
|
L<Stdout|Log::Any::Adapter::Stdout> (save that inside are used descriptor |
106
|
|
|
|
|
|
|
duplicate) |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 SEE ALSO |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
L<Log::Any|Log::Any>, L<Log::Any::Adapter|Log::Any::Adapter>, L<Log::Any::For::Std|Log::Any::For::Std> |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 AUTHORS |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=over 4 |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=item * |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
Mikhail Ivanov <m.ivanych@gmail.com> |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=item * |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Anastasia Zherebtsova <zherebtsova@gmail.com> - translation of documentation |
124
|
|
|
|
|
|
|
into English |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=back |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
This software is copyright (c) 2015 by Mikhail Ivanov. |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
133
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=cut |