line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Log::Any::Adapter::Dispatch; |
2
|
|
|
|
|
|
|
# ABSTRACT: Adapter to use Log::Dispatch with Log::Any |
3
|
|
|
|
|
|
|
our $VERSION = '0.08'; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
4574
|
use Log::Any::Adapter::Util qw(make_method); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
38
|
|
6
|
1
|
|
|
1
|
|
4
|
use Log::Dispatch; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
15
|
|
7
|
1
|
|
|
1
|
|
3
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
14
|
|
8
|
1
|
|
|
1
|
|
2
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
19
|
|
9
|
1
|
|
|
1
|
|
2
|
use base qw(Log::Any::Adapter::Base); |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
210
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub init { |
12
|
2
|
|
|
2
|
0
|
689
|
my $self = shift; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# If a dispatcher was not explicitly passed in, create a new one with the passed arguments. |
15
|
|
|
|
|
|
|
# |
16
|
2
|
50
|
|
|
|
6
|
$_[-2] eq "category" and splice @_, -2, 2; |
17
|
2
|
|
66
|
|
|
11
|
$self->{dispatcher} ||= Log::Dispatch->new(@_); |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# Delegate logging methods to same methods in dispatcher |
21
|
|
|
|
|
|
|
# |
22
|
|
|
|
|
|
|
foreach my $method ( Log::Any->logging_methods() ) { |
23
|
|
|
|
|
|
|
my $log_dispatch_method = $method; |
24
|
|
|
|
|
|
|
$log_dispatch_method =~ s/trace/debug/; |
25
|
|
|
|
|
|
|
__PACKAGE__->delegate_method_to_slot( 'dispatcher', $method, |
26
|
|
|
|
|
|
|
$log_dispatch_method ); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# Delegate detection methods to would_log |
30
|
|
|
|
|
|
|
# |
31
|
|
|
|
|
|
|
foreach my $method ( Log::Any->detection_methods() ) { |
32
|
|
|
|
|
|
|
my $level = substr( $method, 3 ); |
33
|
|
|
|
|
|
|
$level =~ s/trace/debug/; |
34
|
|
|
|
|
|
|
make_method( $method, |
35
|
28
|
|
|
28
|
|
17633
|
sub { my ($self) = @_; return $self->{dispatcher}->would_log($level) } |
|
28
|
|
|
|
|
98
|
|
36
|
|
|
|
|
|
|
); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
1; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
__END__ |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=pod |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=encoding UTF-8 |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 NAME |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
Log::Any::Adapter::Dispatch - Adapter to use Log::Dispatch with Log::Any |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 VERSION |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
version 0.08 |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 SYNOPSIS |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
use Log::Any::Adapter; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Log::Any::Adapter->set('Dispatch', outputs => [[ ... ]]); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
my $dispatcher = Log::Dispatch->new( ... ); |
62
|
|
|
|
|
|
|
Log::Any::Adapter->set('Dispatch', dispatcher => $dispatcher); |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head1 DESCRIPTION |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
This L<Log::Any|Log::Any> adapter uses L<Log::Dispatch|Log::Dispatch> for |
67
|
|
|
|
|
|
|
logging. |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
You may either pass parameters (like I<outputs>) to be passed to |
70
|
|
|
|
|
|
|
C<Log::Dispatch-E<gt>new>, or pass a C<Log::Dispatch> object directly in the |
71
|
|
|
|
|
|
|
I<dispatcher> parameter. |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 SEE ALSO |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
L<Log::Any::Adapter|Log::Any::Adapter>, L<Log::Any|Log::Any>, |
76
|
|
|
|
|
|
|
L<Log::Dispatch|Log::Dispatch> |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 AUTHORS |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=over 4 |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=item * |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Jonathan Swartz <swartz@pobox.com> |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=item * |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Doug Bell <preaction@cpan.org> |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=back |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 CONTRIBUTOR |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=for stopwords Jens Rehsack |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Jens Rehsack <sno@netbsd.org> |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
This software is copyright (c) 2017 by Jonathan Swartz and Doug Bell. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
103
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=cut |