line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Log::Any::Adapter::Catalyst; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: Enable error and status logging in Catalyst Models via Log::Any |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
26610
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
6
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
22
|
|
7
|
1
|
|
|
1
|
|
4
|
use Carp; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
67
|
|
8
|
1
|
|
|
1
|
|
13302
|
use Log::Any::Adapter::Util qw(make_method); |
|
1
|
|
|
|
|
21513
|
|
|
1
|
|
|
|
|
66
|
|
9
|
1
|
|
|
1
|
|
9
|
use base qw(Log::Any::Adapter::Base); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
3224
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '1.00'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub init { |
14
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
15
|
|
|
|
|
|
|
|
16
|
0
|
0
|
|
|
|
|
croak "Log::Any::Adapter->set must be called with the 'logger' parameter\n" |
17
|
|
|
|
|
|
|
. "Typically, in you Catalyst Application Class:\n" |
18
|
|
|
|
|
|
|
. "Log::Any::Adapter->set('Catalyst', logger => __PACKAGE__->log);\n" |
19
|
|
|
|
|
|
|
unless $self->{logger}; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# Connect the Log::Any methods to the appropriate Catalyst::Log method |
23
|
|
|
|
|
|
|
foreach my $method ( Log::Any->logging_and_detection_methods() ) { |
24
|
|
|
|
|
|
|
my $cat_log_method = $method; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# Map log levels down to Catalyst::Log levels where necessary |
27
|
|
|
|
|
|
|
for ($cat_log_method) { |
28
|
|
|
|
|
|
|
s/trace/debug/; |
29
|
|
|
|
|
|
|
s/notice/info/; |
30
|
|
|
|
|
|
|
s/warning/warn/; |
31
|
|
|
|
|
|
|
s/critical|alert|emergency/fatal/; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
__PACKAGE__->delegate_method_to_slot( 'logger', $method, $cat_log_method ); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
1; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
__END__ |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=pod |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 NAME |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Log::Any::Adapter::Catalyst - Enable error and status logging in Catalyst Models via Log::Any |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 VERSION |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
version 1.00 |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 SYNOPSIS |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
In a Catalyst Model, View, etc (anywhere you don't have C<$c>): |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
use Log::Any qw($log); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
$log->debug( "Sent to $c->log() if called from a Catalyst model" ); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
In a your main Catalyst module (MyApp.pm): |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
use Log::Any::Adapter; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Log::Any::Adapter->set('Catalyst', logger => __PACKAGE__->log); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 DESCRIPTION |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
This Log::Any adapter uses L<Catalyst::Log> for logging. L<Catalyst::Log> must |
68
|
|
|
|
|
|
|
be initialized before calling I<set>, but Catalyst takes care of that for you. |
69
|
|
|
|
|
|
|
There are no parameters. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 LOG LEVEL TRANSLATION |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Log levels are translated from L<Log::Any> to L<Catalyst::Log> as follows: |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
trace -> debug |
76
|
|
|
|
|
|
|
debug -> debug |
77
|
|
|
|
|
|
|
info (inform) -> info |
78
|
|
|
|
|
|
|
notice -> info |
79
|
|
|
|
|
|
|
warning (warn) -> warn |
80
|
|
|
|
|
|
|
error (err) -> error |
81
|
|
|
|
|
|
|
critical (crit, fatal) -> fatal |
82
|
|
|
|
|
|
|
alert -> fatal |
83
|
|
|
|
|
|
|
emergency -> fatal |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 SEE ALSO |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
L<Log::Any|Log::Any>, L<Log::Any::Adapter|Log::Any::Adapter>, |
88
|
|
|
|
|
|
|
L<Catalyst|Catalyst>, L<Catalyst::Log|Catalyst::Log> |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 AUTHOR |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Mark Grimes, E<lt>mgrimes@cpan.orgE<gt> |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
This software is copyright (c) 2014 by Mark Grimes, E<lt>mgrimes@cpan.orgE<gt>. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
99
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=cut |