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