| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Log::Dispatch::Colorful; |
|
2
|
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
672
|
use strict; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
78
|
|
|
4
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
62
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
15
|
use base qw( Log::Dispatch::Output ); |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
2585
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
617933
|
use Data::Dumper; |
|
|
2
|
|
|
|
|
23819
|
|
|
|
2
|
|
|
|
|
155
|
|
|
9
|
2
|
|
|
2
|
|
124
|
use Log::Dispatch::Output; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
97
|
|
|
10
|
2
|
|
|
2
|
|
11
|
use Params::Validate qw(validate BOOLEAN SCALAR ARRAYREF CODEREF); |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
148
|
|
|
11
|
2
|
|
|
2
|
|
2680
|
use Term::ANSIColor; |
|
|
2
|
|
|
|
|
29642
|
|
|
|
2
|
|
|
|
|
656
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Params::Validate::validation_options( allow_extra => 1 ); |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our %LEVELS; |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
BEGIN { |
|
20
|
2
|
|
|
2
|
|
7
|
foreach my $level (qw( debug info notice warning err error crit critical alert emerg emergency )) { |
|
21
|
|
|
|
|
|
|
my $sub = sub { |
|
22
|
2
|
|
|
2
|
|
18
|
my $self = shift; |
|
23
|
2
|
|
|
|
|
3
|
my $messages; |
|
24
|
2
|
|
|
|
|
8
|
foreach my $arg (@_) { |
|
25
|
2
|
100
|
|
|
|
8
|
if ( ref $arg ) { |
|
26
|
1
|
|
|
|
|
7
|
$messages = Dumper($arg); |
|
27
|
|
|
|
|
|
|
} |
|
28
|
2
|
|
50
|
|
|
140
|
$messages .= $arg || ''; |
|
29
|
|
|
|
|
|
|
} |
|
30
|
|
|
|
|
|
|
|
|
31
|
2
|
|
|
|
|
47
|
$self->log( level => $level, message => $messages ); |
|
32
|
22
|
|
|
|
|
78
|
}; |
|
33
|
|
|
|
|
|
|
|
|
34
|
22
|
|
|
|
|
48
|
$LEVELS{$level} = 1; |
|
35
|
|
|
|
|
|
|
|
|
36
|
2
|
|
|
2
|
|
23
|
no strict 'refs'; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
76
|
|
|
37
|
2
|
|
|
2
|
|
11
|
no warnings 'redefine'; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
195
|
|
|
38
|
22
|
|
|
|
|
25
|
*{ "Log::Dispatch::" . $level } = $sub; |
|
|
22
|
|
|
|
|
1082
|
|
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub new { |
|
43
|
1
|
|
|
1
|
1
|
32
|
my $proto = shift; |
|
44
|
1
|
|
33
|
|
|
9
|
my $class = ref $proto || $proto; |
|
45
|
|
|
|
|
|
|
|
|
46
|
1
|
|
|
|
|
66
|
my %p = validate( |
|
47
|
|
|
|
|
|
|
@_, |
|
48
|
|
|
|
|
|
|
{ stderr => { |
|
49
|
|
|
|
|
|
|
type => BOOLEAN, |
|
50
|
|
|
|
|
|
|
default => 1 |
|
51
|
|
|
|
|
|
|
}, |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
); |
|
54
|
|
|
|
|
|
|
|
|
55
|
1
|
|
|
|
|
9
|
my $self = bless {}, $class; |
|
56
|
|
|
|
|
|
|
|
|
57
|
1
|
|
|
|
|
14
|
$self->_basic_init(%p); |
|
58
|
|
|
|
|
|
|
|
|
59
|
1
|
50
|
|
|
|
37
|
$self->{color} = exists $p{color} ? $p{color} : {}; |
|
60
|
1
|
50
|
|
|
|
5
|
$self->{stderr} = exists $p{stderr} ? $p{stderr} : 1; |
|
61
|
|
|
|
|
|
|
|
|
62
|
1
|
|
|
|
|
14
|
my @collbacks = $self->_get_callbacks(%p); |
|
63
|
|
|
|
|
|
|
unshift @collbacks, sub { |
|
64
|
2
|
|
|
2
|
|
31
|
my %p = @_; |
|
65
|
|
|
|
|
|
|
|
|
66
|
2
|
50
|
|
|
|
11
|
if ( $self->{color}->{ $p{level} }->{text} ) { |
|
67
|
2
|
|
|
|
|
13
|
$p{message} = color( $self->{color}->{ $p{level} }->{text} ) . $p{message} . color('reset'); |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
|
|
70
|
2
|
50
|
|
|
|
94
|
if ( $self->{color}->{ $p{level} }->{background} ) { |
|
71
|
2
|
|
|
|
|
10
|
$p{message} = color( 'on_' . $self->{color}->{ $p{level} }->{background} ) . $p{message} . color('reset'); |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
2
|
|
|
|
|
77
|
$p{message}; |
|
75
|
1
|
|
|
|
|
16
|
}; |
|
76
|
|
|
|
|
|
|
|
|
77
|
1
|
|
|
|
|
4
|
$self->{callbacks} = \@collbacks; |
|
78
|
|
|
|
|
|
|
|
|
79
|
1
|
|
|
|
|
5
|
return $self; |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub log { |
|
83
|
2
|
|
|
2
|
1
|
4
|
my $self = shift; |
|
84
|
|
|
|
|
|
|
|
|
85
|
2
|
|
|
|
|
68
|
my %p = validate( @_, { level => { type => SCALAR }, } ); |
|
86
|
|
|
|
|
|
|
|
|
87
|
2
|
50
|
|
|
|
20
|
return unless $self->_should_log( $p{level} ); |
|
88
|
|
|
|
|
|
|
|
|
89
|
2
|
50
|
|
|
|
45
|
$p{message} = $self->_apply_callbacks(%p) |
|
90
|
|
|
|
|
|
|
if $self->{callbacks}; |
|
91
|
|
|
|
|
|
|
|
|
92
|
2
|
|
|
|
|
19
|
$self->log_message(%p); |
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub log_message { |
|
96
|
2
|
|
|
2
|
1
|
5
|
my $self = shift; |
|
97
|
2
|
|
|
|
|
6
|
my %p = @_; |
|
98
|
|
|
|
|
|
|
|
|
99
|
2
|
50
|
|
|
|
7
|
if ( $self->{stderr} ) { |
|
100
|
2
|
|
|
|
|
14
|
print STDERR $p{message}; |
|
101
|
|
|
|
|
|
|
} |
|
102
|
|
|
|
|
|
|
else { |
|
103
|
0
|
|
|
|
|
|
print STDOUT $p{message}; |
|
104
|
|
|
|
|
|
|
} |
|
105
|
|
|
|
|
|
|
} |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
1; |
|
108
|
|
|
|
|
|
|
__END__ |