| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
2
|
|
|
2
|
|
9595
|
use 5.008; |
|
|
2
|
|
|
|
|
10
|
|
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Log::Log4perl::Appender::ScreenColoredLevels::UsingMyColors; |
|
4
|
2
|
|
|
2
|
|
13
|
use strict; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
53
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
13
|
use warnings; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
67
|
|
|
7
|
2
|
|
|
2
|
|
12
|
no warnings; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
153
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.113'; |
|
10
|
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
1399
|
use Term::ANSIColor qw(:constants color colored); |
|
|
2
|
|
|
|
|
17062
|
|
|
|
2
|
|
|
|
|
3537
|
|
|
12
|
2
|
|
|
2
|
|
1098
|
use Log::Log4perl::Level; |
|
|
2
|
|
|
|
|
3863
|
|
|
|
2
|
|
|
|
|
10
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=encoding utf8 |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 NAME |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
Log::Log4perl::Appender::ScreenColoredLevels::UsingMyColors - Colorize messages according to level amd my colors |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
use Log::Log4perl::Appender::ScreenColoredLevels::UsingMyColors; |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
use Log::Log4perl qw(:easy); |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
Log::Log4perl->init(\ <<'EOT'); |
|
29
|
|
|
|
|
|
|
log4perl.category = DEBUG, Screen |
|
30
|
|
|
|
|
|
|
log4perl.appender.Screen = Log::Log4perl::Appender::ScreenColoredLevels::UsingMyColors |
|
31
|
|
|
|
|
|
|
log4perl.appender.Screen.layout = Log::Log4perl::Layout::PatternLayout |
|
32
|
|
|
|
|
|
|
log4perl.appender.Screen.layout.ConversionPattern = [%p] %d %F{1} %L> %m %n |
|
33
|
|
|
|
|
|
|
log4perl.appender.Screen.color.trace = cyan |
|
34
|
|
|
|
|
|
|
log4perl.appender.Screen.color.debug = default |
|
35
|
|
|
|
|
|
|
log4perl.appender.Screen.color.info = green |
|
36
|
|
|
|
|
|
|
log4perl.appender.Screen.color.warn = default |
|
37
|
|
|
|
|
|
|
log4perl.appender.Screen.color.error = default |
|
38
|
|
|
|
|
|
|
log4perl.appender.Screen.color.fatal = red |
|
39
|
|
|
|
|
|
|
EOT |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=over 4 |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=item new |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=cut |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub new { |
|
51
|
0
|
|
|
0
|
1
|
|
my( $class, @options ) = @_; |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
#print STDERR "Options are ", Dumper( \@options ), "\n"; |
|
54
|
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
my $self = { |
|
56
|
|
|
|
|
|
|
name => "unknown name", |
|
57
|
|
|
|
|
|
|
stderr => 1, |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
@options, |
|
60
|
|
|
|
|
|
|
}; |
|
61
|
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
my %trace_color; |
|
63
|
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
@trace_color{ qw(trace debug info error warn fatal) } = ( '' ) x 6; |
|
65
|
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
my %Allowed = map { $_, 1 } @{ $Term::ANSIColor::EXPORT_TAGS{constants} }; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
foreach my $level ( qw( trace debug info error warn fatal) ) { |
|
69
|
0
|
0
|
|
|
|
|
next unless exists $self->{color}{$level}; |
|
70
|
0
|
0
|
|
|
|
|
next if lc $self->{color}{$level} eq 'default'; |
|
71
|
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
my @b = map { uc } split /\s+/, $self->{color}{$level}; |
|
|
0
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
foreach my $b ( @b ) { |
|
75
|
0
|
0
|
|
|
|
|
die "Illegal color $b" unless exists $Allowed{ $b }; |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
$trace_color{ $level } = $self->{color}{$level}; |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
$self->{trace_color} = \%trace_color; |
|
82
|
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
bless $self, $class; |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub _trace_color { |
|
87
|
0
|
|
|
0
|
|
|
my( $self, $level ) = @_; |
|
88
|
|
|
|
|
|
|
|
|
89
|
0
|
0
|
|
|
|
|
$self->{trace_color}{ lc $level } || ''; |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=item log |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=cut |
|
95
|
|
|
|
|
|
|
|
|
96
|
2
|
|
|
2
|
|
976
|
BEGIN { $Term::ANSIColor::EACHLINE = "\n" }; |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub log { |
|
99
|
0
|
|
|
0
|
1
|
|
my( $self, %params ) = @_; |
|
100
|
2
|
|
|
2
|
|
16
|
no strict 'refs'; |
|
|
2
|
|
|
|
|
6
|
|
|
|
2
|
|
|
|
|
199
|
|
|
101
|
|
|
|
|
|
|
|
|
102
|
0
|
0
|
|
|
|
|
print { $self->{stderr} ? *STDERR : select } |
|
103
|
|
|
|
|
|
|
colored( |
|
104
|
|
|
|
|
|
|
$params{message}, |
|
105
|
|
|
|
|
|
|
$self->_trace_color( $params{log4p_level} ) |
|
106
|
0
|
|
|
|
|
|
); |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
} |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=back |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
This appender acts like L<Log::Log4perl::Appender::ScreenColoredLevels>, but |
|
115
|
|
|
|
|
|
|
you get to choose the colors. You can choose any of the constants from |
|
116
|
|
|
|
|
|
|
L<Term::ANSIColor>. |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 TO DO |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
L<Log::Log4perl::Appender::ScreenColoredLevels>, L<Term::ANSIColor> |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 SOURCE AVAILABILITY |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
This source is on GitHub: |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
https://github.com/briandfoy/log-log4perl-appender-screencoloredlevels-usingmycolors |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head1 AUTHOR |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
brian d foy, C<< <bdfoy@cpan.org> >> |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
Copyright © 2008-2021, brian d foy <bdfoy@cpan.org>. All rights reserved. |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
You may redistribute this under the terms of the Artistic License 2.0. |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=cut |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
1; |