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