line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Log::Fu::Color; |
2
|
5
|
|
|
5
|
|
24
|
use strict; |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
167
|
|
3
|
5
|
|
|
5
|
|
26
|
use warnings; |
|
5
|
|
|
|
|
15
|
|
|
5
|
|
|
|
|
134
|
|
4
|
5
|
|
|
5
|
|
24
|
use Log::Fu::Common; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
325
|
|
5
|
5
|
|
|
5
|
|
22
|
use Log::Fu::Common qw(:levels); |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
605
|
|
6
|
5
|
|
|
5
|
|
23
|
use base qw(Exporter); |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
1131
|
|
7
|
|
|
|
|
|
|
our @EXPORT = qw(fu_colorize); |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $USE_COLOR = 1; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
BEGIN { |
12
|
5
|
50
|
33
|
5
|
|
75
|
if ($ENV{LOG_FU_NO_COLOR} || $ENV{ANSI_COLORS_DISABLED}) { |
13
|
0
|
|
|
|
|
0
|
$USE_COLOR = 0; |
14
|
|
|
|
|
|
|
} else { |
15
|
5
|
|
|
|
|
9
|
eval { |
16
|
5
|
|
|
|
|
1895
|
require Term::Terminfo; |
17
|
0
|
|
|
|
|
0
|
Term::Terminfo->import(); |
18
|
0
|
|
|
|
|
0
|
my $ti = Term::Terminfo->new(); |
19
|
0
|
|
|
|
|
0
|
my $n_colors = $ti->getnum("colors"); |
20
|
0
|
0
|
|
|
|
0
|
if ($n_colors < 8) { |
21
|
|
|
|
|
|
|
#Color logging disabled: |
22
|
0
|
|
|
|
|
0
|
die "Must have >= 16 colors!"; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
}; |
25
|
5
|
50
|
|
|
|
27
|
if ($@) { |
26
|
5
|
|
|
|
|
293
|
$USE_COLOR = 0; |
27
|
|
|
|
|
|
|
} else { |
28
|
0
|
|
|
|
|
0
|
$USE_COLOR = 1; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
my %COLORS = ( |
33
|
|
|
|
|
|
|
YELLOW => 3, |
34
|
|
|
|
|
|
|
WHITE => 7, |
35
|
|
|
|
|
|
|
MAGENTA => 5, |
36
|
|
|
|
|
|
|
CYAN => 6, |
37
|
|
|
|
|
|
|
BLUE => 4, |
38
|
|
|
|
|
|
|
GREEN => 2, |
39
|
|
|
|
|
|
|
RED => 1, |
40
|
|
|
|
|
|
|
BLACK => 0, |
41
|
|
|
|
|
|
|
); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
use constant { |
44
|
5
|
|
|
|
|
533
|
COLOR_FG => 3, |
45
|
|
|
|
|
|
|
COLOR_BG => 4, |
46
|
|
|
|
|
|
|
COLOR_BRIGHT_FG => 1, |
47
|
|
|
|
|
|
|
COLOR_INTENSE_FG=> 9, |
48
|
|
|
|
|
|
|
COLOR_DIM_FG => 2 |
49
|
5
|
|
|
5
|
|
25
|
}; |
|
5
|
|
|
|
|
10
|
|
50
|
|
|
|
|
|
|
use constant { |
51
|
5
|
|
|
|
|
1241
|
COLOR_RESET => "\33[0m" |
52
|
5
|
|
|
5
|
|
25
|
}; |
|
5
|
|
|
|
|
8
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub fu_colorize { |
56
|
0
|
|
|
0
|
0
|
|
my ($level_number,$message) = @_; |
57
|
0
|
|
|
|
|
|
my $fmt_begin = "\033["; |
58
|
0
|
|
|
|
|
|
my $fmt_end = COLOR_RESET; |
59
|
0
|
0
|
0
|
|
|
|
if ($level_number == LOG_ERR || $level_number == LOG_CRIT) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
$fmt_begin .= sprintf("%s;%s%sm", COLOR_BRIGHT_FG, COLOR_FG, $COLORS{RED}); |
61
|
|
|
|
|
|
|
} elsif ($level_number == LOG_WARN) { |
62
|
0
|
|
|
|
|
|
$fmt_begin .= sprintf("%s%sm", COLOR_FG, $COLORS{YELLOW}); |
63
|
|
|
|
|
|
|
} elsif ($level_number == LOG_DEBUG) { |
64
|
0
|
|
|
|
|
|
$fmt_begin .= sprintf("%s;%s%sm", COLOR_DIM_FG, COLOR_FG, $COLORS{WHITE}); |
65
|
|
|
|
|
|
|
} else { |
66
|
0
|
|
|
|
|
|
$fmt_begin = ""; |
67
|
0
|
|
|
|
|
|
$fmt_end = ""; |
68
|
|
|
|
|
|
|
} |
69
|
0
|
|
|
|
|
|
$message = $fmt_begin . $message . $fmt_end; |
70
|
0
|
|
|
|
|
|
return $message; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
1; |