line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojo::Log::Colored; |
2
|
5
|
|
|
5
|
|
582935
|
use Mojo::Base 'Mojo::Log'; |
|
5
|
|
|
|
|
647381
|
|
|
5
|
|
|
|
|
35
|
|
3
|
5
|
|
|
5
|
|
121339
|
use Term::ANSIColor 'colored'; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
263
|
|
4
|
|
|
|
|
|
|
|
5
|
5
|
|
|
5
|
|
3155
|
use if $^O eq "MSWin32", "Win32::Console::ANSI"; |
|
5
|
|
|
|
|
61
|
|
|
5
|
|
|
|
|
30
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = "0.04"; |
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
|
52
|
100
|
|
52
|
1
|
92019
|
return $_[0]->_format if @_ == 1; |
25
|
|
|
|
|
|
|
|
26
|
10
|
|
|
|
|
22
|
my ( $self, $format ) = @_; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
return $self->_format( |
29
|
|
|
|
|
|
|
sub { |
30
|
|
|
|
|
|
|
# Prevent having the end escape sequence at the start of the line |
31
|
42
|
|
|
42
|
|
180
|
local $Term::ANSIColor::EACHLINE = "\n"; |
32
|
|
|
|
|
|
|
# only add colors if we have a color for this level |
33
|
|
|
|
|
|
|
exists $self->colors->{ $_[1] } |
34
|
42
|
100
|
|
|
|
84
|
? colored( $format->(@_), $self->colors->{ $_[1] } ) |
35
|
|
|
|
|
|
|
: $format->(@_); |
36
|
|
|
|
|
|
|
} |
37
|
10
|
|
|
|
|
82
|
)->_format; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# use the default logger format based on the Mojo version we're running under |
41
|
|
|
|
|
|
|
sub _default_format; |
42
|
|
|
|
|
|
|
if ($Mojolicious::VERSION && $Mojolicious::VERSION >= 9) { |
43
|
|
|
|
|
|
|
*_default_format = sub { |
44
|
1
|
|
|
1
|
|
70
|
'[' . localtime(shift) . '] [' . shift() . '] ' . join(' ', @_, "\n"); |
45
|
|
|
|
|
|
|
}; |
46
|
|
|
|
|
|
|
} else { |
47
|
|
|
|
|
|
|
*_default_format = sub { |
48
|
6
|
|
|
6
|
|
235
|
'[' . localtime(shift) . '] [' . shift() . '] ' . join("\n", @_, ''); |
49
|
|
|
|
|
|
|
}; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
1; |
53
|
|
|
|
|
|
|
__END__ |