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