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