cleanup whitespace
[scpubgit/Object-Remote.git] / lib / Object / Remote / Logging.pm
CommitLineData
3a966220 1package Object::Remote::Logging;
2
21988035 3use Moo;
4use Scalar::Util qw(blessed);
5use Object::Remote::Logging::Logger;
3a966220 6
21988035 7extends 'Log::Contextual';
3a966220 8
21988035 9sub router {
7d063a6a 10 our $Router_Instance ||= do {
11 require Object::Remote::Logging::Router;
12 Object::Remote::Logging::Router->new;
13 }
21988035 14}
3a966220 15
21988035 16sub arg_levels {
7d063a6a 17 return [qw( trace debug verbose info warn error )];
23591f5f 18}
3a966220 19
21988035 20#this is invoked on all nodes
23591f5f 21sub init_logging {
7d063a6a 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 );
28
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 41sub 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
481;
49