line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Fix::log; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
105614
|
use Catmandu::Sane; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
6
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '1.2020'; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
8
|
use Moo; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
8
|
1
|
|
|
1
|
|
779
|
use Catmandu; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
5
|
|
9
|
1
|
|
|
1
|
|
251
|
use namespace::clean; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
5
|
|
10
|
1
|
|
|
1
|
|
853
|
use Catmandu::Fix::Has; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
with 'Catmandu::Fix::Inlineable', 'Catmandu::Logger'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has message => (fix_arg => 1); |
15
|
|
|
|
|
|
|
has level => (fix_opt => 1); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub fix { |
18
|
1
|
|
|
1
|
0
|
43
|
my ($self, $data) = @_; |
19
|
1
|
|
50
|
|
|
8
|
my $id = $data->{_id} // '<undef>'; |
20
|
1
|
|
50
|
|
|
7
|
my $level = $self->level // 'INFO'; |
21
|
|
|
|
|
|
|
|
22
|
1
|
50
|
|
|
|
10
|
if ($level |
23
|
|
|
|
|
|
|
=~ /^(trace|debug|info|notice|warn|error|critical|alert|emergency)$/i) |
24
|
|
|
|
|
|
|
{ |
25
|
1
|
|
|
|
|
5
|
my $lvl = lc $level; |
26
|
1
|
|
|
|
|
22
|
$self->log->$lvl(sprintf "%s : %s\n", $id, $self->message); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
1
|
|
|
|
|
2273
|
$data; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
1; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
__END__ |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=pod |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head1 NAME |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
Catmandu::Fix::log - Log::Any logger as fix |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 SYNOPSIS |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
log('test123') |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
log('hello world' , level:WARN) |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head1 DESCRIPTION |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
This fix add debugging capabilities to fixes. To use it via the command line you need to add the |
51
|
|
|
|
|
|
|
'-D' option to your script. E.g. |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
echo '{}' | catmandu convert -D to YAML --fix 'log("help!", level:WARN)' |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
By default all logging messages have a level:INFO and will not be displayed unless |
56
|
|
|
|
|
|
|
a log4perl configuration is in place (see below). Using log messages without a |
57
|
|
|
|
|
|
|
log4perl configuration requires a log level of 'WARN', 'ERROR' or 'FATAL'. |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 CONFIGURATION |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
To have a full control over the log messages, create a 'catmandu.yml' with a |
62
|
|
|
|
|
|
|
'log4perl' section as shown below: |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
$ cat catmandu.yml |
65
|
|
|
|
|
|
|
log4perl: | |
66
|
|
|
|
|
|
|
log4perl.category.Catmandu::Fix::log=TRACE,OUT |
67
|
|
|
|
|
|
|
log4perl.appender.OUT=Log::Log4perl::Appender::Screen |
68
|
|
|
|
|
|
|
log4perl.appender.OUT.stderr=1 |
69
|
|
|
|
|
|
|
log4perl.appender.OUT.utf8=1 |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
log4perl.appender.OUT.layout=PatternLayout |
72
|
|
|
|
|
|
|
log4perl.appender.OUT.layout.ConversionPattern=%d [%P] - %p %l time=%r : %m%n |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Using this configuration file all logging messages are written to the screen |
75
|
|
|
|
|
|
|
(stderr output). With this configuration in place use the L<catmandu> command |
76
|
|
|
|
|
|
|
with the -D option to view the logging output: |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
$ echo '{}' | catmandu convert -D to YAML --fix 'log("help!")' > output.yaml 2> log.txt |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
The Unix redirections '>' and '2>' can be used to write the output of the |
81
|
|
|
|
|
|
|
catmandu command and the logging in two separate files. |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 SEE ALSO |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
L<Catmandu::Fix>, L<Catmandu::Logger> , L<Log::log4perl> |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=cut |