line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MojoX::Log::Dispatch; |
2
|
4
|
|
|
4
|
|
137060
|
use warnings; |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
148
|
|
3
|
4
|
|
|
4
|
|
25
|
use strict; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
154
|
|
4
|
4
|
|
|
4
|
|
22
|
use base 'Mojo::Log'; |
|
4
|
|
|
|
|
15
|
|
|
4
|
|
|
|
|
4564
|
|
5
|
4
|
|
|
4
|
|
504023
|
use Carp 'croak'; |
|
4
|
|
|
|
|
12
|
|
|
4
|
|
|
|
|
249
|
|
6
|
4
|
|
|
4
|
|
16376
|
use Log::Dispatch; |
|
4
|
|
|
|
|
115666
|
|
|
4
|
|
|
|
|
152
|
|
7
|
4
|
|
|
4
|
|
6356
|
use Log::Dispatch::File; |
|
4
|
|
|
|
|
23168
|
|
|
4
|
|
|
|
|
124
|
|
8
|
4
|
|
|
4
|
|
4676
|
use Log::Dispatch::Screen; |
|
4
|
|
|
|
|
3451
|
|
|
4
|
|
|
|
|
4394
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
MojoX::Log::Dispatch - Log::Dispatch For Mojo |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 VERSION |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
Version 0.06 |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=cut |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our $VERSION = '0.1'; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
__PACKAGE__->attr( |
26
|
|
|
|
|
|
|
'handle' => sub { |
27
|
|
|
|
|
|
|
my $self = shift; |
28
|
|
|
|
|
|
|
my $dispatcher; |
29
|
|
|
|
|
|
|
if ($self->callbacks) |
30
|
|
|
|
|
|
|
{ |
31
|
|
|
|
|
|
|
$dispatcher = Log::Dispatch->new(callbacks => $self->callbacks); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
else |
34
|
|
|
|
|
|
|
{ |
35
|
|
|
|
|
|
|
$dispatcher = Log::Dispatch->new(@_); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
if ($self->path) |
39
|
|
|
|
|
|
|
{ |
40
|
|
|
|
|
|
|
$dispatcher->add(Log::Dispatch::File->new( 'name' => '_default_log_obj', |
41
|
|
|
|
|
|
|
'min_level' => $self->level, |
42
|
|
|
|
|
|
|
'filename' => $self->path, |
43
|
|
|
|
|
|
|
'mode' => 'append' ) |
44
|
|
|
|
|
|
|
); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
else |
48
|
|
|
|
|
|
|
{ |
49
|
|
|
|
|
|
|
# Create a logging object that will log to STDERR by default |
50
|
|
|
|
|
|
|
$dispatcher->add(Log::Dispatch::Screen->new( 'name' => '_default_log_obj', |
51
|
|
|
|
|
|
|
'min_level' => $self->level, |
52
|
|
|
|
|
|
|
'stderr' => 1 ) |
53
|
|
|
|
|
|
|
); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
return $dispatcher; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
__PACKAGE__->attr('callbacks'); |
60
|
|
|
|
|
|
|
__PACKAGE__->attr('remove_default_log_obj' => 1); |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
0
|
1
|
0
|
sub dispatcher { return shift->handle } |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
#some methods from Log::Dispatch |
66
|
|
|
|
|
|
|
sub add { |
67
|
10
|
|
|
10
|
1
|
28591
|
my $self = shift; |
68
|
10
|
|
|
|
|
382
|
my $l = $self->handle->add(@_); |
69
|
|
|
|
|
|
|
#remove default log object that log to STDERR? |
70
|
10
|
50
|
|
|
|
452
|
$self->remove('_default_log_obj') if $self->remove_default_log_obj; |
71
|
10
|
|
|
|
|
173
|
return $l; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
10
|
|
|
10
|
1
|
371
|
sub remove { return shift->handle->remove(@_) } |
75
|
2
|
|
|
2
|
1
|
474
|
sub output { return shift->handle->output(@_)} |
76
|
30
|
|
|
30
|
1
|
890
|
sub would_log {return shift->handle->would_log(@_)} |
77
|
0
|
|
|
0
|
1
|
0
|
sub log_to {return shift->handle->log_to(@_) } |
78
|
0
|
|
|
0
|
1
|
0
|
sub level_is_valid { return shift->handle->level_is_valid(@_) } |
79
|
0
|
|
|
0
|
1
|
0
|
sub log_and_die { return shift->handle->log_and_die(@_) } |
80
|
0
|
|
|
0
|
1
|
0
|
sub log_and_croak { return shift->handle->log_and_croak(@_) } |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub log |
84
|
|
|
|
|
|
|
{ |
85
|
11
|
|
|
11
|
1
|
679
|
my ($self, $level, @msgs) = @_; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# Check log level |
88
|
11
|
|
|
|
|
23
|
$level = lc $level; |
89
|
11
|
100
|
66
|
|
|
51
|
return $self unless $level && $self->is_level($level); |
90
|
|
|
|
|
|
|
|
91
|
9
|
|
|
|
|
625
|
$self->handle->log('level' => $level, 'message' => @msgs); |
92
|
9
|
|
|
|
|
1936
|
return $self; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
|
97
|
0
|
|
|
0
|
1
|
0
|
sub fatal { shift->log('emergency', @_) } |
98
|
0
|
|
|
0
|
1
|
0
|
sub emergency { shift->log('emergency', @_) } |
99
|
0
|
|
|
0
|
1
|
0
|
sub alert { shift->log('alert', @_) } |
100
|
0
|
|
|
0
|
1
|
0
|
sub critical { shift->log('critical', @_) } |
101
|
1
|
|
|
1
|
1
|
8
|
sub warning { shift->log('warning', @_) } |
102
|
0
|
|
|
0
|
1
|
0
|
sub warn { shift->log('warning', @_) } |
103
|
0
|
|
|
0
|
1
|
0
|
sub notice { shift->log('notice', @_) } |
104
|
|
|
|
|
|
|
#short alias syslog style |
105
|
0
|
|
|
0
|
1
|
0
|
sub err { shift->log('error', @_) } |
106
|
1
|
|
|
1
|
1
|
61
|
sub crit { shift->log('critical', @_) } |
107
|
2
|
|
|
2
|
1
|
64
|
sub emerg { shift->log('emergency', @_) } |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub is_level { |
112
|
30
|
|
|
30
|
1
|
3612
|
my ($self, $level) = @_; |
113
|
30
|
50
|
|
|
|
72
|
return 0 unless $level; |
114
|
30
|
|
|
|
|
58
|
$level = lc $level; |
115
|
30
|
|
|
|
|
71
|
return $self->would_log($level); |
116
|
|
|
|
|
|
|
} |
117
|
2
|
|
|
2
|
1
|
1006
|
sub is_fatal { shift->is_level('emergency') } |
118
|
2
|
|
|
2
|
1
|
1156
|
sub is_emergency { shift->is_level('emergency') } |
119
|
1
|
|
|
1
|
1
|
567
|
sub is_alert { shift->is_level('alert') } |
120
|
1
|
|
|
1
|
1
|
602
|
sub is_critical { shift->is_level('critical') } |
121
|
1
|
|
|
1
|
1
|
10
|
sub is_warning { shift->is_level('warning') } |
122
|
1
|
|
|
1
|
1
|
927
|
sub is_warn { shift->is_level('warning') } |
123
|
1
|
|
|
1
|
1
|
541
|
sub is_notice { shift->is_level('notice') } |
124
|
1
|
|
|
1
|
1
|
562
|
sub is_err { shift->is_level('error') } |
125
|
1
|
|
|
1
|
1
|
511
|
sub is_crit { shift->is_level('critical') } |
126
|
2
|
|
|
2
|
1
|
503
|
sub is_emerg { shift->is_level('emergency') } |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
1; # End of MojoX::Log::Dispatch |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
__END__ |