X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=scpubgit%2FObject-Remote.git;a=blobdiff_plain;f=lib%2FObject%2FRemote%2FLogging.pm;h=e7da88a2f9b4c28b3f3f441cd9ec70b5306a4d41;hp=25831acf1fc42f372bf681d8ba93390e1746bd0f;hb=9de32e1d7e5f896e00a8d14aeb2103be94b047f2;hpb=f7ea4120db80a6feb33053e6bcb0f983b71f7394 diff --git a/lib/Object/Remote/Logging.pm b/lib/Object/Remote/Logging.pm index 25831ac..e7da88a 100644 --- a/lib/Object/Remote/Logging.pm +++ b/lib/Object/Remote/Logging.pm @@ -1,15 +1,60 @@ package Object::Remote::Logging; -use strictures 1; +use Moo; +use Scalar::Util qw(blessed); +use Object::Remote::Logging::Logger; -use Log::Contextual qw( :log ); -use Object::Remote::LogRouter; +extends 'Log::Contextual'; -use base qw(Log::Contextual); +sub router { + our $Router_Instance ||= do { + require Object::Remote::Logging::Router; + Object::Remote::Logging::Router->new; + } +} -sub arg_router { return $_[1] if defined $_[1]; our $Router_Instance ||= Object::Remote::LogRouter->new } +#log level descriptions +#info - standard log level - normal program output for the end user +#warn - output for program that is executing quietly +#error - output for program that is running more quietly +#fatal - it is not possible to continue execution; this level is as quiet as is possible +#verbose - output for program executing verbosely (-v) +#debug - output for program running more verbosely (-v -v) +#trace - output for program running extremely verbosely (-v -v -v) +sub arg_levels { + #the order of the log levels is significant with the + #most verbose level being first in the list and the + #most quiet as the last item + return [qw( trace debug verbose info warn error fatal )]; +} -sub init_node { my $n = `hostname`; chomp($n); $_[0]->add_child_router("[node $n]", __PACKAGE__->arg_router) } +#this is invoked on all nodes +sub init_logging { + my $level = $ENV{OBJECT_REMOTE_LOG_LEVEL}; + return unless defined $level; + my $logger = Object::Remote::Logging::Logger->new( + min_level => lc($level), + level_names => Object::Remote::Logging::arg_levels(), + ); + + #TODO check on speed of string compare against a hash with a single key + router()->connect(sub { + return unless $_[1]->{controller} eq __PACKAGE__; + #skip things from remote hosts because they log to STDERR + #when OBJECT_REMOTE_LOG_LEVEL is in effect + return if $_[1]->{remote}->{connection_id}; + $logger + }); +} + +#this is invoked by the controlling node +#on the remote nodes +sub init_logging_forwarding { + my ($self, %controller_info) = @_; + + router()->_remote_metadata({ connection_id => $controller_info{connection_id} }); + router()->_forward_destination($controller_info{router}); +} 1;