Commit | Line | Data |
3a966220 |
1 | package Object::Remote::Logging; |
2 | |
21988035 |
3 | use Moo; |
4 | use Scalar::Util qw(blessed); |
5 | use Object::Remote::Logging::Logger; |
3a966220 |
6 | |
21988035 |
7 | extends 'Log::Contextual'; |
3a966220 |
8 | |
21988035 |
9 | sub router { |
10 | our $Router_Instance ||= do { |
11 | require Object::Remote::Logging::Router; |
12 | Object::Remote::Logging::Router->new; |
13 | } |
14 | } |
3a966220 |
15 | |
21988035 |
16 | sub arg_levels { |
17 | return [qw( trace debug verbose info warn error )]; |
23591f5f |
18 | } |
3a966220 |
19 | |
21988035 |
20 | #this is invoked on all nodes |
23591f5f |
21 | sub init_logging { |
21988035 |
22 | my $level = $ENV{OBJECT_REMOTE_LOG_LEVEL}; |
23 | return unless defined $level; |
24 | my $logger = Object::Remote::Logging::Logger->new( |
25 | min_level => lc($level), |
26 | level_names => Object::Remote::Logging::arg_levels(), |
27 | ); |
23591f5f |
28 | |
21988035 |
29 | #TODO check on speed of string compare against a hash with a single key |
30 | router()->connect(sub { |
31 | return unless $_[1]->{controller} eq __PACKAGE__; |
32 | #skip things from remote hosts because they log to STDERR |
33 | #when OBJECT_REMOTE_LOG_LEVEL is in effect |
34 | return if $_[1]->{remote}->{connection_id}; |
35 | $logger |
36 | }); |
23591f5f |
37 | } |
38 | |
21988035 |
39 | #this is invoked by the controlling node |
40 | #on the remote nodes |
23591f5f |
41 | sub init_logging_forwarding { |
21988035 |
42 | my ($self, %controller_info) = @_; |
43 | |
44 | router()->_remote_metadata({ connection_id => $controller_info{connection_id} }); |
45 | router()->_forward_destination($controller_info{router}); |
23591f5f |
46 | } |
3a966220 |
47 | |
48 | 1; |
49 | |