| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Object::Remote::Logging::Router; |
|
2
|
|
|
|
|
|
|
|
|
3
|
18
|
|
|
18
|
|
135882
|
use Moo; |
|
|
18
|
|
|
|
|
9712
|
|
|
|
18
|
|
|
|
|
135
|
|
|
4
|
18
|
|
|
18
|
|
9370
|
use Scalar::Util qw(weaken); |
|
|
18
|
|
|
|
|
54
|
|
|
|
18
|
|
|
|
|
1193
|
|
|
5
|
18
|
|
|
18
|
|
6227
|
use Sys::Hostname; |
|
|
18
|
|
|
|
|
16968
|
|
|
|
18
|
|
|
|
|
16998
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
with 'Log::Contextual::Role::Router'; |
|
8
|
|
|
|
|
|
|
with 'Object::Remote::Role::LogForwarder'; |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has _connections => ( is => 'ro', required => 1, default => sub { [] } ); |
|
11
|
|
|
|
|
|
|
has _remote_metadata => ( is => 'rw' ); |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
145
|
0
|
|
sub before_import { } |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
145
|
0
|
|
sub after_import { } |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub _get_loggers { |
|
18
|
15666
|
|
|
15666
|
|
66452
|
my ($self, %metadata) = @_; |
|
19
|
15666
|
|
|
|
|
28919
|
my $package = $metadata{caller_package}; |
|
20
|
15666
|
|
|
|
|
27386
|
my $level = $metadata{message_level}; |
|
21
|
15666
|
|
|
|
|
29787
|
my $is_level = "is_$level"; |
|
22
|
15666
|
|
|
|
|
25257
|
my $need_clean = 0; |
|
23
|
15666
|
|
|
|
|
28317
|
my @loggers; |
|
24
|
|
|
|
|
|
|
|
|
25
|
15666
|
|
|
|
|
27239
|
foreach my $selector (@{$self->_connections}) { |
|
|
15666
|
|
|
|
|
48901
|
|
|
26
|
68
|
100
|
|
|
|
158
|
unless(defined $selector) { |
|
27
|
8
|
|
|
|
|
16
|
$need_clean = 1; |
|
28
|
8
|
|
|
|
|
17
|
next; |
|
29
|
|
|
|
|
|
|
} |
|
30
|
|
|
|
|
|
|
|
|
31
|
60
|
|
|
|
|
370
|
foreach my $logger ($selector->($package, { %metadata })) { |
|
32
|
60
|
50
|
|
|
|
196
|
next unless defined $logger; |
|
33
|
60
|
50
|
|
|
|
199
|
next unless $logger->$is_level; |
|
34
|
60
|
|
|
|
|
506
|
push(@loggers, $logger); |
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
|
|
38
|
15666
|
100
|
|
|
|
41048
|
$self->_clean_connections if $need_clean; |
|
39
|
|
|
|
|
|
|
|
|
40
|
15666
|
|
|
|
|
64537
|
return @loggers; |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
#overloadable so a router can invoke a logger |
|
44
|
|
|
|
|
|
|
#in a different way |
|
45
|
|
|
|
|
|
|
sub _invoke_logger { |
|
46
|
60
|
|
|
60
|
|
114
|
my ($self, $logger, $level_name, $content, $metadata) = @_; |
|
47
|
|
|
|
|
|
|
#Invoking the logger like this gets all available data to the |
|
48
|
|
|
|
|
|
|
#logging object with out losing any information from the datastructure. |
|
49
|
|
|
|
|
|
|
#This is not a backwards compatible way to invoke the loggers |
|
50
|
|
|
|
|
|
|
#but it enables a lot of flexibility in the logger. |
|
51
|
|
|
|
|
|
|
#The l-c router could have this method invoke the logger in |
|
52
|
|
|
|
|
|
|
#a backwards compatible way and router sub classes invoke |
|
53
|
|
|
|
|
|
|
#it in non-backwards compatible ways if desired |
|
54
|
60
|
|
|
|
|
191
|
$logger->$level_name($content, $metadata); |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
#overloadable so forwarding can have the updated |
|
58
|
|
|
|
|
|
|
#metadata but does not have to wrap get_loggers |
|
59
|
|
|
|
|
|
|
#which has too many drawbacks |
|
60
|
|
|
|
|
|
|
sub _deliver_message { |
|
61
|
|
|
|
|
|
|
my ($self, %message_info) = @_; |
|
62
|
|
|
|
|
|
|
my @loggers = $self->_get_loggers(%message_info); |
|
63
|
|
|
|
|
|
|
my $generator = $message_info{message_sub}; |
|
64
|
|
|
|
|
|
|
my $args = $message_info{message_args}; |
|
65
|
|
|
|
|
|
|
my $level = $message_info{message_level}; |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
return unless @loggers > 0; |
|
68
|
|
|
|
|
|
|
#this is the point where the user provided log message code block is executed |
|
69
|
|
|
|
|
|
|
my @content = $generator->(@$args); |
|
70
|
|
|
|
|
|
|
foreach my $logger (@loggers) { |
|
71
|
|
|
|
|
|
|
$self->_invoke_logger($logger, $level, \@content, \%message_info); |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub handle_log_request { |
|
76
|
15666
|
|
|
15666
|
0
|
1065077
|
my ($self, %message_info) = @_; |
|
77
|
15666
|
|
|
|
|
34575
|
my $level = $message_info{message_level}; |
|
78
|
15666
|
|
|
|
|
27755
|
my $package = $message_info{caller_package}; |
|
79
|
15666
|
|
|
|
|
24902
|
my $need_clean = 0; |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
#caller_level is useless when log forwarding is in place |
|
82
|
|
|
|
|
|
|
#so we won't tempt people with using it |
|
83
|
15666
|
|
|
|
|
28549
|
my $caller_level = delete $message_info{caller_level}; |
|
84
|
15666
|
|
|
|
|
47575
|
$message_info{object_remote} = $self->_remote_metadata; |
|
85
|
15666
|
|
|
|
|
29672
|
$message_info{timestamp} = time; |
|
86
|
15666
|
|
|
|
|
93022
|
$message_info{pid} = $$; |
|
87
|
15666
|
|
|
|
|
51618
|
$message_info{hostname} = hostname; |
|
88
|
|
|
|
|
|
|
|
|
89
|
15666
|
|
|
|
|
161564
|
my @caller_info = caller($caller_level); |
|
90
|
15666
|
|
|
|
|
35021
|
$message_info{filename} = $caller_info[1]; |
|
91
|
15666
|
|
|
|
|
26974
|
$message_info{line} = $caller_info[2]; |
|
92
|
|
|
|
|
|
|
|
|
93
|
15666
|
|
|
|
|
79716
|
@caller_info = caller($caller_level + 1); |
|
94
|
15666
|
|
|
|
|
33147
|
$message_info{method} = $caller_info[3]; |
|
95
|
15666
|
100
|
|
|
|
173341
|
$message_info{method} =~ s/^${package}::// if defined $message_info{method}; |
|
96
|
|
|
|
|
|
|
|
|
97
|
15666
|
|
|
|
|
489284
|
$self->_deliver_message(%message_info); |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub connect { |
|
101
|
17
|
|
|
17
|
0
|
1347
|
my ($self, $destination, $is_weak) = @_; |
|
102
|
17
|
|
|
|
|
35
|
my $wrapped; |
|
103
|
|
|
|
|
|
|
|
|
104
|
17
|
100
|
|
|
|
69
|
if (ref($destination) ne 'CODE') { |
|
105
|
2
|
|
|
3
|
|
10
|
$wrapped = sub { $destination }; |
|
|
3
|
|
|
|
|
27
|
|
|
106
|
|
|
|
|
|
|
} else { |
|
107
|
15
|
|
|
|
|
30
|
$wrapped = $destination; |
|
108
|
|
|
|
|
|
|
} |
|
109
|
|
|
|
|
|
|
|
|
110
|
17
|
|
|
|
|
35
|
push(@{$self->_connections}, $wrapped); |
|
|
17
|
|
|
|
|
76
|
|
|
111
|
17
|
100
|
|
|
|
88
|
weaken($self->_connections->[-1]) if $is_weak; |
|
112
|
|
|
|
|
|
|
} |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub _clean_connections { |
|
115
|
8
|
|
|
8
|
|
18
|
my ($self) = @_; |
|
116
|
8
|
|
|
|
|
14
|
@{$self->{_connections}} = grep { defined } @{$self->{_connections}}; |
|
|
8
|
|
|
|
|
31
|
|
|
|
36
|
|
|
|
|
61
|
|
|
|
8
|
|
|
|
|
22
|
|
|
117
|
|
|
|
|
|
|
} |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
1; |