line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MooseX::Role::Loggable; |
2
|
|
|
|
|
|
|
$MooseX::Role::Loggable::VERSION = '0.114'; |
3
|
|
|
|
|
|
|
# ABSTRACT: Extensive, yet simple, logging role using Log::Dispatchouli |
4
|
|
|
|
|
|
|
|
5
|
6
|
|
|
6
|
|
39265
|
use strict; |
|
6
|
|
|
|
|
8
|
|
|
6
|
|
|
|
|
140
|
|
6
|
6
|
|
|
6
|
|
17
|
use warnings; |
|
6
|
|
|
|
|
7
|
|
|
6
|
|
|
|
|
111
|
|
7
|
|
|
|
|
|
|
|
8
|
6
|
|
|
6
|
|
21
|
use Carp (); |
|
6
|
|
|
|
|
8
|
|
|
6
|
|
|
|
|
65
|
|
9
|
6
|
|
|
6
|
|
2344
|
use Safe::Isa; |
|
6
|
|
|
|
|
2059
|
|
|
6
|
|
|
|
|
609
|
|
10
|
6
|
|
|
6
|
|
25
|
use Moo::Role; |
|
6
|
|
|
|
|
5
|
|
|
6
|
|
|
|
|
30
|
|
11
|
6
|
|
|
6
|
|
4009
|
use MooX::Types::MooseLike::Base qw; |
|
6
|
|
|
|
|
25577
|
|
|
6
|
|
|
|
|
398
|
|
12
|
6
|
|
|
6
|
|
2597
|
use Sub::Quote 'quote_sub'; |
|
6
|
|
|
|
|
13539
|
|
|
6
|
|
|
|
|
246
|
|
13
|
6
|
|
|
6
|
|
2697
|
use Log::Dispatchouli; |
|
6
|
|
|
|
|
126508
|
|
|
6
|
|
|
|
|
177
|
|
14
|
6
|
|
|
6
|
|
2300
|
use namespace::autoclean; |
|
6
|
|
|
|
|
41163
|
|
|
6
|
|
|
|
|
16
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my %attr_meth_map = ( |
17
|
|
|
|
|
|
|
'logger_facility' => 'facility', |
18
|
|
|
|
|
|
|
'logger_ident' => 'ident', |
19
|
|
|
|
|
|
|
'log_to_file' => 'to_file', |
20
|
|
|
|
|
|
|
'log_to_stdout' => 'to_stdout', |
21
|
|
|
|
|
|
|
'log_to_stderr' => 'to_stderr', |
22
|
|
|
|
|
|
|
'log_fail_fatal' => 'fail_fatal', |
23
|
|
|
|
|
|
|
'log_muted' => 'muted', |
24
|
|
|
|
|
|
|
'log_quiet_fatal' => 'quiet_fatal', |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
has 'debug' => ( |
28
|
|
|
|
|
|
|
'is' => 'ro', |
29
|
|
|
|
|
|
|
'isa' => Bool, |
30
|
|
|
|
|
|
|
'default' => sub {0}, |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
has 'logger_facility' => ( |
34
|
|
|
|
|
|
|
'is' => 'ro', |
35
|
|
|
|
|
|
|
'isa' => Str, |
36
|
|
|
|
|
|
|
'default' => sub {'local6'}, |
37
|
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
has 'logger_ident' => ( |
40
|
|
|
|
|
|
|
'is' => 'ro', |
41
|
|
|
|
|
|
|
'isa' => Str, |
42
|
|
|
|
|
|
|
'default' => sub { ref shift }, |
43
|
|
|
|
|
|
|
); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
has 'log_to_file' => ( |
46
|
|
|
|
|
|
|
'is' => 'ro', |
47
|
|
|
|
|
|
|
'isa' => Bool, |
48
|
|
|
|
|
|
|
'default' => sub {0}, |
49
|
|
|
|
|
|
|
); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
has 'log_to_stdout' => ( |
52
|
|
|
|
|
|
|
'is' => 'ro', |
53
|
|
|
|
|
|
|
'isa' => Bool, |
54
|
|
|
|
|
|
|
'default' => sub {0}, |
55
|
|
|
|
|
|
|
); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
has 'log_to_stderr' => ( |
58
|
|
|
|
|
|
|
'is' => 'ro', |
59
|
|
|
|
|
|
|
'isa' => Bool, |
60
|
|
|
|
|
|
|
'default' => sub {0}, |
61
|
|
|
|
|
|
|
); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
has 'log_file' => ( |
64
|
|
|
|
|
|
|
'is' => 'ro', |
65
|
|
|
|
|
|
|
'isa' => Str, |
66
|
|
|
|
|
|
|
'predicate' => 'has_log_file', |
67
|
|
|
|
|
|
|
); |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
has 'log_path' => ( |
70
|
|
|
|
|
|
|
'is' => 'ro', |
71
|
|
|
|
|
|
|
'isa' => Str, |
72
|
|
|
|
|
|
|
'predicate' => 'has_log_path', |
73
|
|
|
|
|
|
|
); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
has 'log_pid' => ( |
76
|
|
|
|
|
|
|
'is' => 'ro', |
77
|
|
|
|
|
|
|
'isa' => Bool, |
78
|
|
|
|
|
|
|
'default' => sub {1}, |
79
|
|
|
|
|
|
|
); |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
has 'log_fail_fatal' => ( |
82
|
|
|
|
|
|
|
'is' => 'ro', |
83
|
|
|
|
|
|
|
'isa' => Bool, |
84
|
|
|
|
|
|
|
'default' => sub {1}, |
85
|
|
|
|
|
|
|
); |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
has 'log_muted' => ( |
88
|
|
|
|
|
|
|
'is' => 'ro', |
89
|
|
|
|
|
|
|
'isa' => Bool, |
90
|
|
|
|
|
|
|
'default' => sub {0}, |
91
|
|
|
|
|
|
|
); |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
has 'log_quiet_fatal' => ( |
94
|
|
|
|
|
|
|
'is' => 'ro', |
95
|
|
|
|
|
|
|
'isa' => quote_sub( |
96
|
|
|
|
|
|
|
q{ |
97
|
|
|
|
|
|
|
use Safe::Isa; |
98
|
|
|
|
|
|
|
$_[0] || $_[0]->$_isa( ref [] ) |
99
|
|
|
|
|
|
|
or die "$_[0] must be a string or arrayref" |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
), |
102
|
|
|
|
|
|
|
'default' => sub {'stderr'}, |
103
|
|
|
|
|
|
|
); |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
has 'logger' => ( |
106
|
|
|
|
|
|
|
'is' => 'lazy', |
107
|
|
|
|
|
|
|
'isa' => quote_sub( |
108
|
|
|
|
|
|
|
q{ |
109
|
|
|
|
|
|
|
use Safe::Isa; |
110
|
|
|
|
|
|
|
$_[0]->$_isa('Log::Dispatchouli') || |
111
|
|
|
|
|
|
|
$_[0]->$_isa('Log::Dispatchouli::Proxy') |
112
|
|
|
|
|
|
|
or die "$_[0] must be a Log::Dispatchouli object"; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
), |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
'handles' => [ |
117
|
|
|
|
|
|
|
qw/ |
118
|
|
|
|
|
|
|
log log_fatal log_debug |
119
|
|
|
|
|
|
|
set_debug clear_debug set_prefix clear_prefix set_muted clear_muted |
120
|
|
|
|
|
|
|
/ |
121
|
|
|
|
|
|
|
], |
122
|
|
|
|
|
|
|
); |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub _build_logger { |
125
|
7
|
|
|
7
|
|
5255
|
my $self = shift; |
126
|
7
|
|
|
|
|
10
|
my %optional; |
127
|
|
|
|
|
|
|
|
128
|
7
|
|
|
|
|
13
|
foreach my $option (qw) { |
129
|
14
|
|
|
|
|
20
|
my $method = "has_$option"; |
130
|
14
|
100
|
|
|
|
58
|
if ( $self->$method ) { |
131
|
1
|
|
|
|
|
5
|
$optional{$option} = $self->$option; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
7
|
|
|
|
|
147
|
my $logger = Log::Dispatchouli->new( |
136
|
|
|
|
|
|
|
{ |
137
|
|
|
|
|
|
|
'debug' => $self->debug, |
138
|
|
|
|
|
|
|
'ident' => $self->logger_ident, |
139
|
|
|
|
|
|
|
'facility' => $self->logger_facility, |
140
|
|
|
|
|
|
|
'to_file' => $self->log_to_file, |
141
|
|
|
|
|
|
|
'to_stdout' => $self->log_to_stdout, |
142
|
|
|
|
|
|
|
'to_stderr' => $self->log_to_stderr, |
143
|
|
|
|
|
|
|
'log_pid' => $self->log_pid, |
144
|
|
|
|
|
|
|
'fail_fatal' => $self->log_fail_fatal, |
145
|
|
|
|
|
|
|
'muted' => $self->log_muted, |
146
|
|
|
|
|
|
|
'quiet_fatal' => $self->log_quiet_fatal, |
147
|
|
|
|
|
|
|
%optional, |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
); |
150
|
|
|
|
|
|
|
|
151
|
7
|
|
|
|
|
51653
|
return $logger; |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
# if we already have a logger, use its values |
155
|
|
|
|
|
|
|
sub BUILDARGS { |
156
|
13
|
|
|
13
|
1
|
55437
|
my $class = shift; |
157
|
13
|
|
|
|
|
30
|
my %args = @_; |
158
|
13
|
|
|
|
|
43
|
my @items = qw< |
159
|
|
|
|
|
|
|
debug logger_facility logger_ident |
160
|
|
|
|
|
|
|
log_to_file log_to_stdout log_to_stderr log_file log_path |
161
|
|
|
|
|
|
|
log_pid log_fail_fatal log_muted log_quiet_fatal |
162
|
|
|
|
|
|
|
>; |
163
|
|
|
|
|
|
|
|
164
|
13
|
100
|
|
|
|
39
|
if ( exists $args{'logger'} ) { |
165
|
|
|
|
|
|
|
$args{'logger'}->$_isa('Log::Dispatchouli') |
166
|
5
|
100
|
100
|
|
|
15
|
|| $args{'logger'}->$_isa('Log::Dispatchouli::Proxy') |
167
|
|
|
|
|
|
|
or Carp::croak('logger must be a Log::Dispatchouli object'); |
168
|
|
|
|
|
|
|
|
169
|
4
|
|
|
|
|
66
|
foreach my $item (@items) { |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
# if value is overridden, don't touch it |
172
|
|
|
|
|
|
|
my $attr |
173
|
|
|
|
|
|
|
= exists $attr_meth_map{$item} |
174
|
48
|
100
|
|
|
|
61
|
? $attr_meth_map{$item} |
175
|
|
|
|
|
|
|
: $item; |
176
|
|
|
|
|
|
|
|
177
|
48
|
100
|
|
|
|
48
|
if ( exists $args{$item} ) { |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
# override logger configuration |
180
|
1
|
|
|
|
|
5
|
$args{'logger'}{$attr} = $args{$item}; |
181
|
|
|
|
|
|
|
} else { |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
# override our attributes if it's in logger |
184
|
|
|
|
|
|
|
exists $args{'logger'}{$attr} |
185
|
47
|
100
|
|
|
|
82
|
and $args{$item} = $args{'logger'}{$attr}; |
186
|
|
|
|
|
|
|
} |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
|
190
|
12
|
|
|
|
|
201
|
return {%args}; |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
sub log_fields { |
194
|
1
|
|
|
1
|
1
|
1006
|
my $self = shift; |
195
|
1
|
|
|
|
|
2
|
my $warning |
196
|
|
|
|
|
|
|
= '[MooseX::Role::Loggable] Calling ->log_fields() is deprecated, ' |
197
|
|
|
|
|
|
|
. 'it will be removed in the next version'; |
198
|
|
|
|
|
|
|
|
199
|
1
|
|
|
|
|
4
|
$self->log( { 'level' => 'warning' }, $warning ); |
200
|
1
|
|
|
|
|
1615
|
Carp::carp($warning); |
201
|
|
|
|
|
|
|
|
202
|
1
|
|
|
|
|
389
|
return ( 'logger' => $self->logger ); |
203
|
|
|
|
|
|
|
} |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
1; |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
__END__ |