line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojo::Log::Role::Format; |
2
|
1
|
|
|
1
|
|
7055
|
use Mojo::Base -role; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
9
|
|
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
522
|
use overload (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
431
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
has logf_serialize => sub { \&_serialize }; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub logf { |
11
|
4
|
|
|
4
|
1
|
7385
|
my ($self, $level, $format, @args) = @_; |
12
|
4
|
100
|
|
|
|
15
|
$self->$level(@args ? sprintf $format, $self->logf_serialize->(@args) : $format) |
|
|
50
|
|
|
|
|
|
13
|
|
|
|
|
|
|
if $self->is_level($level); |
14
|
4
|
|
|
|
|
687
|
return $self; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub _serialize { |
18
|
3
|
50
|
|
3
|
|
18
|
my @args = map { ref $_ eq 'CODE' ? $_->() : $_ } @_; |
|
4
|
|
|
|
|
14
|
|
19
|
|
|
|
|
|
|
|
20
|
3
|
|
|
|
|
8
|
local $Data::Dumper::Indent = 0; |
21
|
3
|
|
50
|
|
|
13
|
local $Data::Dumper::Maxdepth = $Data::Dumper::Maxdepth || 2; |
22
|
3
|
|
|
|
|
7
|
local $Data::Dumper::Pair = ':'; |
23
|
3
|
|
|
|
|
5
|
local $Data::Dumper::Quotekeys = 1; |
24
|
3
|
|
|
|
|
5
|
local $Data::Dumper::Sortkeys = 1; |
25
|
3
|
|
|
|
|
5
|
local $Data::Dumper::Terse = 1; |
26
|
3
|
|
|
|
|
5
|
local $Data::Dumper::Useqq = 1; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
return map { |
29
|
3
|
100
|
|
|
|
4
|
!defined($_) ? 'undef' |
|
4
|
50
|
|
|
|
56
|
|
|
|
50
|
|
|
|
|
|
30
|
|
|
|
|
|
|
: overload::Method($_, q("")) ? "$_" |
31
|
|
|
|
|
|
|
: ref($_) ? Data::Dumper::Dumper($_) |
32
|
|
|
|
|
|
|
: $_; |
33
|
|
|
|
|
|
|
} @args; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
1; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=encoding utf8 |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 NAME |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Mojo::Log::Role::Format - Add sprintf logging to Mojo::Log |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 SYNOPSIS |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
use Mojo::Log; |
47
|
|
|
|
|
|
|
my $log = Mojo::Log->new->with_roles('+Format')->level('debug'); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# [info] cool beans |
50
|
|
|
|
|
|
|
$log->logf(info => 'cool %s', 'beans'); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# [warn] serializing {"data":"structures"} |
53
|
|
|
|
|
|
|
$log->logf(warn => 'serializing %s', {data => 'structures'}); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 DESCRIPTION |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
L is a L role which allow you to log with |
58
|
|
|
|
|
|
|
a format like C, avoid "Use of uninitialized" warnings and will |
59
|
|
|
|
|
|
|
also serialize data-structures and objects. |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head2 logf_serialize |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
$cb = $log->logf_serialize; |
66
|
|
|
|
|
|
|
$log = $log->logf_serialize(sub (@args) { ... }); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
This attribute must hold a callback that will be used to serialize the arguments |
69
|
|
|
|
|
|
|
passed to L. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
The default callback uses L with some modifications, but these |
72
|
|
|
|
|
|
|
settings are currently EXPERIMENTAL and subject to change: |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
$Data::Dumper::Indent = 0; |
75
|
|
|
|
|
|
|
$Data::Dumper::Maxdepth = $Data::Dumper::Maxdepth || 2; |
76
|
|
|
|
|
|
|
$Data::Dumper::Pair = ':'; |
77
|
|
|
|
|
|
|
$Data::Dumper::Quotekeys = 1; |
78
|
|
|
|
|
|
|
$Data::Dumper::Sortkeys = 1; |
79
|
|
|
|
|
|
|
$Data::Dumper::Terse = 1; |
80
|
|
|
|
|
|
|
$Data::Dumper::Useqq = 1; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 METHODS |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head2 logf |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
$log = $log->logf($level => $format, @args); |
87
|
|
|
|
|
|
|
$log = $log->logf($level => $message); |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
See L. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 AUTHOR |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Jan Henning Thorsen |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
This library is free software. You can redistribute it and/or modify it under |
98
|
|
|
|
|
|
|
the same terms as Perl itself. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 SEE ALSO |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
L |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=cut |