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=d8bfdba721b2527c399b96c4254df2d759b140f4;hp=e7da88a2f9b4c28b3f3f441cd9ec70b5306a4d41;hb=eb49c7df7a88ac9114188e9eeb1480205bea97ee;hpb=9de32e1d7e5f896e00a8d14aeb2103be94b047f2 diff --git a/lib/Object/Remote/Logging.pm b/lib/Object/Remote/Logging.pm index e7da88a..d8bfdba 100644 --- a/lib/Object/Remote/Logging.pm +++ b/lib/Object/Remote/Logging.pm @@ -3,9 +3,12 @@ package Object::Remote::Logging; use Moo; use Scalar::Util qw(blessed); use Object::Remote::Logging::Logger; +use Exporter::Declare; extends 'Log::Contextual'; +exports(qw( router arg_levels )); + sub router { our $Router_Instance ||= do { require Object::Remote::Logging::Router; @@ -31,15 +34,26 @@ sub arg_levels { #this is invoked on all nodes sub init_logging { my $level = $ENV{OBJECT_REMOTE_LOG_LEVEL}; + my $format = $ENV{OBJECT_REMOTE_LOG_FORMAT}; + #TODO allow the selections value to be * so it selects everything + my $selections = $ENV{OBJECT_REMOTE_LOG_SELECTIONS}; + my %controller_should_log; + return unless defined $level; + $format = "[%l %r] %s" unless defined $format; + $selections = __PACKAGE__ unless defined $selections; + %controller_should_log = map { $_ => 1 } split(' ', $selections); + my $logger = Object::Remote::Logging::Logger->new( - min_level => lc($level), + min_level => lc($level), format => $format, 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__; + my $controller = $_[1]->{controller}; +# warn $controller; + return unless $controller_should_log{$controller}; #skip things from remote hosts because they log to STDERR #when OBJECT_REMOTE_LOG_LEVEL is in effect return if $_[1]->{remote}->{connection_id};