alarm() in fatnode is now set to value of connection timeout and is always used even...
[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 {
c0b2df05 10 our $Router_Instance ||= do {
11 require Object::Remote::Logging::Router;
12 Object::Remote::Logging::Router->new;
13 }
4e446335 14}
5e2b2229 15
9de32e1d 16#log level descriptions
17#info - standard log level - normal program output for the end user
18#warn - output for program that is executing quietly
19#error - output for program that is running more quietly
20#fatal - it is not possible to continue execution; this level is as quiet as is possible
21#verbose - output for program executing verbosely (-v)
22#debug - output for program running more verbosely (-v -v)
23#trace - output for program running extremely verbosely (-v -v -v)
4e446335 24sub arg_levels {
9de32e1d 25 #the order of the log levels is significant with the
26 #most verbose level being first in the list and the
27 #most quiet as the last item
28 return [qw( trace debug verbose info warn error fatal )];
4a9fa1a5 29}
5e2b2229 30
4e446335 31#this is invoked on all nodes
4a9fa1a5 32sub init_logging {
c0b2df05 33 my $level = $ENV{OBJECT_REMOTE_LOG_LEVEL};
34 return unless defined $level;
35 my $logger = Object::Remote::Logging::Logger->new(
36 min_level => lc($level),
37 level_names => Object::Remote::Logging::arg_levels(),
38 );
39
40 #TODO check on speed of string compare against a hash with a single key
41 router()->connect(sub {
42 return unless $_[1]->{controller} eq __PACKAGE__;
43 #skip things from remote hosts because they log to STDERR
44 #when OBJECT_REMOTE_LOG_LEVEL is in effect
45 return if $_[1]->{remote}->{connection_id};
46 $logger
47 });
4a9fa1a5 48}
49
4e446335 50#this is invoked by the controlling node
51#on the remote nodes
4a9fa1a5 52sub init_logging_forwarding {
4e446335 53 my ($self, %controller_info) = @_;
54
55 router()->_remote_metadata({ connection_id => $controller_info{connection_id} });
56 router()->_forward_destination($controller_info{router});
4a9fa1a5 57}
5e2b2229 58
591;
60