replaced entire logging subsystem with one that is fully operational with the followi...
[scpubgit/Object-Remote.git] / lib / Object / Remote / Logging.pm
CommitLineData
5e2b2229 1package Object::Remote::Logging;
2
4e446335 3use Moo;
4use Scalar::Util qw(blessed);
5use Object::Remote::Logging::Logger;
5e2b2229 6
4e446335 7extends 'Log::Contextual';
5e2b2229 8
4e446335 9sub router {
10 our $Router_Instance ||= do {
11 require Object::Remote::Logging::Router;
12 Object::Remote::Logging::Router->new;
13 }
14}
5e2b2229 15
4e446335 16sub arg_levels {
17 return [qw( trace debug verbose info warn error )];
4a9fa1a5 18}
5e2b2229 19
4e446335 20#this is invoked on all nodes
4a9fa1a5 21sub init_logging {
4e446335 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 );
4a9fa1a5 28
4e446335 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 });
4a9fa1a5 37}
38
4e446335 39#this is invoked by the controlling node
40#on the remote nodes
4a9fa1a5 41sub init_logging_forwarding {
4e446335 42 my ($self, %controller_info) = @_;
43
44 router()->_remote_metadata({ connection_id => $controller_info{connection_id} });
45 router()->_forward_destination($controller_info{router});
4a9fa1a5 46}
5e2b2229 47
481;
49