line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojo::Log::Colored; |
2
|
3
|
|
|
3
|
|
664842
|
use Mojo::Base 'Mojo::Log'; |
|
3
|
|
|
|
|
341978
|
|
|
3
|
|
|
|
|
26
|
|
3
|
3
|
|
|
3
|
|
62762
|
use Term::ANSIColor 'colored'; |
|
3
|
|
|
|
|
22127
|
|
|
3
|
|
|
|
|
10776
|
|
4
|
|
|
|
|
|
|
|
5
|
3
|
|
|
3
|
|
2314
|
use if $^O eq "MSWin32", "Win32::Console::ANSI"; |
|
3
|
|
|
|
|
39
|
|
|
3
|
|
|
|
|
19
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = "0.03"; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
has 'colors' => sub { |
10
|
|
|
|
|
|
|
return { |
11
|
|
|
|
|
|
|
debug => "bold bright_white", |
12
|
|
|
|
|
|
|
info => "bold bright_blue", |
13
|
|
|
|
|
|
|
warn => "bold green", |
14
|
|
|
|
|
|
|
error => "bold yellow", |
15
|
|
|
|
|
|
|
fatal => "bold yellow on_red", |
16
|
|
|
|
|
|
|
}; |
17
|
|
|
|
|
|
|
}; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
has _format => sub { |
20
|
|
|
|
|
|
|
shift->format( \&_default_format ); |
21
|
|
|
|
|
|
|
}; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub format { |
24
|
48
|
100
|
|
48
|
1
|
128718
|
return $_[0]->_format if @_ == 1; |
25
|
|
|
|
|
|
|
|
26
|
8
|
|
|
|
|
21
|
my ( $self, $format ) = @_; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
return $self->_format( |
29
|
|
|
|
|
|
|
sub { |
30
|
|
|
|
|
|
|
# Prevent having the end escape sequence at the start of the line |
31
|
40
|
|
|
40
|
|
179
|
local $Term::ANSIColor::EACHLINE = "\n"; |
32
|
|
|
|
|
|
|
# only add colors if we have a color for this level |
33
|
|
|
|
|
|
|
exists $self->colors->{ $_[1] } |
34
|
40
|
100
|
|
|
|
91
|
? colored( $format->(@_), $self->colors->{ $_[1] } ) |
35
|
|
|
|
|
|
|
: $format->(@_); |
36
|
|
|
|
|
|
|
} |
37
|
8
|
|
|
|
|
48
|
)->_format; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub _default_format { |
41
|
5
|
|
|
5
|
|
420
|
'[' . localtime(shift) . '] [' . shift() . '] ' . join "\n", @_, ''; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
1; |
45
|
|
|
|
|
|
|
__END__ |