| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Log::Dispatch::Screen; |
|
2
|
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
134538
|
use strict; |
|
|
3
|
|
|
|
|
11
|
|
|
|
3
|
|
|
|
|
87
|
|
|
4
|
3
|
|
|
3
|
|
15
|
use warnings; |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
119
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '2.71'; |
|
7
|
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
1826
|
use Encode qw( encode ); |
|
|
3
|
|
|
|
|
31643
|
|
|
|
3
|
|
|
|
|
218
|
|
|
9
|
3
|
|
|
3
|
|
23
|
use IO::Handle; |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
115
|
|
|
10
|
3
|
|
|
3
|
|
396
|
use Log::Dispatch::Types; |
|
|
3
|
|
|
|
|
7
|
|
|
|
3
|
|
|
|
|
25
|
|
|
11
|
3
|
|
|
3
|
|
85646
|
use Params::ValidationCompiler qw( validation_for ); |
|
|
3
|
|
|
|
|
18072
|
|
|
|
3
|
|
|
|
|
160
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
3
|
|
|
3
|
|
25
|
use base qw( Log::Dispatch::Output ); |
|
|
3
|
|
|
|
|
8
|
|
|
|
3
|
|
|
|
|
1243
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
{ |
|
16
|
|
|
|
|
|
|
my $validator = validation_for( |
|
17
|
|
|
|
|
|
|
params => { |
|
18
|
|
|
|
|
|
|
stderr => { |
|
19
|
|
|
|
|
|
|
type => t('Bool'), |
|
20
|
|
|
|
|
|
|
default => 1, |
|
21
|
|
|
|
|
|
|
}, |
|
22
|
|
|
|
|
|
|
utf8 => { |
|
23
|
|
|
|
|
|
|
type => t('Bool'), |
|
24
|
|
|
|
|
|
|
default => 0, |
|
25
|
|
|
|
|
|
|
}, |
|
26
|
|
|
|
|
|
|
}, |
|
27
|
|
|
|
|
|
|
slurpy => 1, |
|
28
|
|
|
|
|
|
|
); |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub new { |
|
31
|
4
|
|
|
4
|
0
|
17950
|
my $class = shift; |
|
32
|
4
|
|
|
|
|
100
|
my %p = $validator->(@_); |
|
33
|
|
|
|
|
|
|
|
|
34
|
4
|
|
|
|
|
157
|
my $self = bless { map { $_ => delete $p{$_} } qw( stderr utf8 ) }, |
|
|
8
|
|
|
|
|
31
|
|
|
35
|
|
|
|
|
|
|
$class; |
|
36
|
|
|
|
|
|
|
|
|
37
|
4
|
|
|
|
|
30
|
$self->_basic_init(%p); |
|
38
|
|
|
|
|
|
|
|
|
39
|
4
|
|
|
|
|
27
|
return $self; |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub log_message { |
|
44
|
1
|
|
|
1
|
0
|
2
|
my $self = shift; |
|
45
|
1
|
|
|
|
|
4
|
my %p = @_; |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# This is a bit gross but it's important that we print directly to the |
|
48
|
|
|
|
|
|
|
# STDOUT or STDERR handle for backwards compatibility. Various modules |
|
49
|
|
|
|
|
|
|
# have tests which rely on this, so we can't open a new filehandle to fd 1 |
|
50
|
|
|
|
|
|
|
# or 2 and use that. |
|
51
|
|
|
|
|
|
|
my $message |
|
52
|
1
|
50
|
|
|
|
7
|
= $self->{utf8} ? encode( 'UTF-8', $p{message} ) : $p{message}; |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
## no critic (InputOutput::RequireCheckedSyscalls) |
|
55
|
1
|
50
|
|
|
|
208
|
if ( $self->{stderr} ) { |
|
56
|
0
|
|
|
|
|
0
|
print STDERR $message; |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
else { |
|
59
|
1
|
|
|
|
|
63
|
print STDOUT $message; |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
1; |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# ABSTRACT: Object for logging to the screen |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
__END__ |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=pod |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=encoding UTF-8 |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 NAME |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
Log::Dispatch::Screen - Object for logging to the screen |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 VERSION |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
version 2.71 |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
use Log::Dispatch; |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
my $log = Log::Dispatch->new( |
|
86
|
|
|
|
|
|
|
outputs => [ |
|
87
|
|
|
|
|
|
|
[ |
|
88
|
|
|
|
|
|
|
'Screen', |
|
89
|
|
|
|
|
|
|
min_level => 'debug', |
|
90
|
|
|
|
|
|
|
stderr => 1, |
|
91
|
|
|
|
|
|
|
newline => 1 |
|
92
|
|
|
|
|
|
|
] |
|
93
|
|
|
|
|
|
|
], |
|
94
|
|
|
|
|
|
|
); |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
$log->alert("I'm searching the city for sci-fi wasabi"); |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
This module provides an object for logging to the screen (really C<STDOUT> or |
|
101
|
|
|
|
|
|
|
C<STDERR>). |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
Note that a newline will I<not> be added automatically at the end of a message |
|
104
|
|
|
|
|
|
|
by default. To do that, pass C<< newline => 1 >>. |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=for Pod::Coverage new log_message |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 CONSTRUCTOR |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
The constructor takes the following parameters in addition to the standard |
|
111
|
|
|
|
|
|
|
parameters documented in L<Log::Dispatch::Output>: |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=over 4 |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=item * stderr (0 or 1) |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Indicates whether or not logging information should go to C<STDERR>. If false, |
|
118
|
|
|
|
|
|
|
logging information is printed to C<STDOUT> instead. |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
This defaults to true. |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=item * utf8 (0 or 1) |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
If this is true, then the output will be encoded using the UTF-8 encoding. If |
|
125
|
|
|
|
|
|
|
you have I<already> applied an encoding layer to the relevant filehandle, |
|
126
|
|
|
|
|
|
|
C<STDOUT> or C<STDERR>, then your output will end up double-encoded if this is |
|
127
|
|
|
|
|
|
|
true. |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
This defaults to false. |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=back |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 SUPPORT |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Bugs may be submitted at L<https://github.com/houseabsolute/Log-Dispatch/issues>. |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 SOURCE |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
The source code repository for Log-Dispatch can be found at L<https://github.com/houseabsolute/Log-Dispatch>. |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head1 AUTHOR |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
Dave Rolsky <autarch@urth.org> |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
This software is Copyright (c) 2023 by Dave Rolsky. |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
This is free software, licensed under: |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
The Artistic License 2.0 (GPL Compatible) |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
The full text of the license can be found in the |
|
154
|
|
|
|
|
|
|
F<LICENSE> file included with this distribution. |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=cut |