line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Log::Dispatch::Screen::Gentoo; |
2
|
|
|
|
|
|
|
# ABSTRACT: Gentoo-colored screen logging output |
3
|
|
|
|
|
|
|
$Log::Dispatch::Screen::Gentoo::VERSION = '0.001'; |
4
|
2
|
|
|
2
|
|
363743
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
45
|
|
5
|
2
|
|
|
2
|
|
6
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
41
|
|
6
|
2
|
|
|
2
|
|
6
|
use parent 'Log::Dispatch::Screen'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
11
|
|
7
|
2
|
|
|
2
|
|
78972
|
use Encode (); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
30
|
|
8
|
2
|
|
|
2
|
|
8
|
use Module::Runtime qw< require_module >; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
16
|
|
9
|
2
|
|
|
2
|
|
908
|
use Term::GentooFunctions ':all'; |
|
2
|
|
|
|
|
12606
|
|
|
2
|
|
|
|
|
1225
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
## no critic qw(Modules::RequireExplicitInclusion) |
12
|
|
|
|
|
|
|
my $encode |
13
|
|
|
|
|
|
|
= require_module('Unicode::UTF8') |
14
|
|
|
|
|
|
|
? sub { Unicode::UTF8::encode_utf8( $_[0] ) } |
15
|
|
|
|
|
|
|
: sub { Encode::encode_utf8( $_[0] ) }; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# einfo |
18
|
|
|
|
|
|
|
# ewarn |
19
|
|
|
|
|
|
|
# eerror |
20
|
|
|
|
|
|
|
# equiet |
21
|
|
|
|
|
|
|
# ebegin |
22
|
|
|
|
|
|
|
# eend |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
our %FUNCTION_MAP = ( |
25
|
|
|
|
|
|
|
'' => sub { einfo( $_[0] ) }, |
26
|
|
|
|
|
|
|
'debug' => sub { einfo( $_[0] ) }, |
27
|
|
|
|
|
|
|
'info' => sub { einfo( $_[0] ) }, |
28
|
|
|
|
|
|
|
'notice' => sub { einfo( $_[0] ) }, |
29
|
|
|
|
|
|
|
'warning' => sub { ewarn( $_[0] ) }, |
30
|
|
|
|
|
|
|
'error' => sub { eerror( $_[0] ) }, |
31
|
|
|
|
|
|
|
'critical' => sub { eerror( $_[0] ) }, |
32
|
|
|
|
|
|
|
'alert' => sub { eerror( $_[0] ) }, |
33
|
|
|
|
|
|
|
'emergency' => sub { eerror( $_[0] ) }, |
34
|
|
|
|
|
|
|
); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub log_message { |
37
|
11
|
|
|
11
|
0
|
16663
|
my ( $self, %p ) = @_; |
38
|
|
|
|
|
|
|
|
39
|
11
|
|
|
|
|
13
|
my $level = $p{'level'}; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
my $message |
42
|
|
|
|
|
|
|
= $self->{'utf8'} |
43
|
|
|
|
|
|
|
? $encode->( $p{'message'} ) |
44
|
11
|
50
|
|
|
|
35
|
: $encode->( $p{'message'} ); |
45
|
|
|
|
|
|
|
|
46
|
11
|
|
33
|
|
|
30
|
my $print_func = $FUNCTION_MAP{$level} //= $FUNCTION_MAP{''}; |
47
|
|
|
|
|
|
|
|
48
|
11
|
50
|
|
|
|
21
|
if ( $self->{'stderr'} ) { |
49
|
|
|
|
|
|
|
# Should be STDERR |
50
|
11
|
|
|
|
|
22
|
$print_func->($message); |
51
|
|
|
|
|
|
|
} else { |
52
|
|
|
|
|
|
|
# Should be STDOUT |
53
|
0
|
|
|
|
|
|
$print_func->($message); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
1; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
__END__ |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=pod |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=encoding UTF-8 |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 NAME |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Log::Dispatch::Screen::Gentoo - Gentoo-colored screen logging output |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 VERSION |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
version 0.001 |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 SYNOPSIS |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
use Log::Dispatch; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
my $log = Log::Dispatch->new( |
78
|
|
|
|
|
|
|
'outputs' => [ |
79
|
|
|
|
|
|
|
[ |
80
|
|
|
|
|
|
|
'Screen::Gentoo', |
81
|
|
|
|
|
|
|
'min_level' => 'debug', |
82
|
|
|
|
|
|
|
'stderr' => 1, |
83
|
|
|
|
|
|
|
'newline' => 1, |
84
|
|
|
|
|
|
|
], |
85
|
|
|
|
|
|
|
], |
86
|
|
|
|
|
|
|
); |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
$log->info('Information'); |
89
|
|
|
|
|
|
|
$log->warning('Uh oh!'); |
90
|
|
|
|
|
|
|
$log->critical('No oh!'); |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 DESCRIPTION |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
This implements a colorful output that uses L<Term::GentooFunctions> to |
95
|
|
|
|
|
|
|
print out the output. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
It also works with indentation when using C<eindent> and C<eoutdent> from |
98
|
|
|
|
|
|
|
L<Term::GentooFunctions>. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
If you have L<Unicode::UTF8> available, it will use that to support UTF-8 |
101
|
|
|
|
|
|
|
character encodings. (This is much faster than L<Encode>.) |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
One limitation this has is that there are only three colors, which means |
104
|
|
|
|
|
|
|
that you cannot see a difference between levels C<debug>, C<notice>, and |
105
|
|
|
|
|
|
|
C<info> which all have a green color, or between C<error>, C<critical>, |
106
|
|
|
|
|
|
|
C<alert>, and C<emergency> which all have a red color. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
At least for now. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 SEE ALSO |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=over 4 |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=item * L<Log::Dispatch::Screen::Color> |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Colors entire lines, not just the beginning. Try it out. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=item * L<Unicode::UTF8> |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=back |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 AUTHOR |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Sawyer X <xsawyerx@cpan.org> |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
This software is Copyright (c) 2017 by Sawyer X. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
This is free software, licensed under: |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
The MIT (X11) License |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=cut |