From: Tyler Riddle Date: Wed, 7 Nov 2012 16:31:22 +0000 (-0800) Subject: env var OBJECT_REMOTE_LOG_SELECTIONS allows selection of 1 or more controller classes... X-Git-Tag: v0.003001_01~82 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=eb49c7df7a88ac9114188e9eeb1480205bea97ee;p=scpubgit%2FObject-Remote.git env var OBJECT_REMOTE_LOG_SELECTIONS allows selection of 1 or more controller classes for logging output --- diff --git a/lib/Object/Remote/FatNode.pm b/lib/Object/Remote/FatNode.pm index fdb2a22..77e6928 100644 --- a/lib/Object/Remote/FatNode.pm +++ b/lib/Object/Remote/FatNode.pm @@ -61,6 +61,7 @@ my @file_names = keys %mods; my @before_inc = grep { filter_not_core() } @file_names; my @after_inc; +#TODO obviously this should be made into a method or configurable some how my $env_pass = ''; if (defined($ENV{OBJECT_REMOTE_LOG_LEVEL})) { my $level = $ENV{OBJECT_REMOTE_LOG_LEVEL}; @@ -70,6 +71,11 @@ if (defined($ENV{OBJECT_REMOTE_LOG_FORMAT})) { my $format = $ENV{OBJECT_REMOTE_LOG_FORMAT}; $env_pass .= '$ENV{OBJECT_REMOTE_LOG_FORMAT} = "' . $format . "\";\n"; } +if (defined($ENV{OBJECT_REMOTE_LOG_SELECTIONS})) { + my $selections = $ENV{OBJECT_REMOTE_LOG_SELECTIONS}; + $env_pass .= '$ENV{OBJECT_REMOTE_LOG_SELECTIONS} = "' . $selections . "\";\n"; +} + my $start = stripspace <<'END_START'; # This chunk of stuff was generated by Object::Remote::FatNode. To find diff --git a/lib/Object/Remote/Logging.pm b/lib/Object/Remote/Logging.pm index d2c92d1..d8bfdba 100644 --- a/lib/Object/Remote/Logging.pm +++ b/lib/Object/Remote/Logging.pm @@ -35,8 +35,15 @@ sub arg_levels { 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), format => $format, level_names => Object::Remote::Logging::arg_levels(), @@ -44,7 +51,9 @@ sub init_logging { #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}; diff --git a/lib/Object/Remote/Logging/Logger.pm b/lib/Object/Remote/Logging/Logger.pm index 83e3a0e..68adaf8 100644 --- a/lib/Object/Remote/Logging/Logger.pm +++ b/lib/Object/Remote/Logging/Logger.pm @@ -67,7 +67,7 @@ sub _create_format_lookup { '%' => '%', t => $self->_render_time($metadata->{timestamp}), r => $self->_render_remote($metadata->{object_remote}), s => $self->_render_log(@$content), l => $level, - p => $metadata->{package}, m => $method, + c => $metadata->{controller}, p => $metadata->{package}, m => $method, f => $metadata->{filename}, i => $metadata->{line}, }; diff --git a/lib/Object/Remote/Logging/Router.pm b/lib/Object/Remote/Logging/Router.pm index 838da82..1bd62fa 100644 --- a/lib/Object/Remote/Logging/Router.pm +++ b/lib/Object/Remote/Logging/Router.pm @@ -46,6 +46,18 @@ sub _get_loggers { return @loggers; } +sub _invoke_logger { + my ($self, $logger, $level_name, $content, $metadata) = @_; + #Invoking the logger like this gets all available data to the + #logging object with out losing any information from the structure. + #This is not a backwards compatible way to invoke the loggers + #but it enables a lot of flexibility in the logger. + #The l-c router could have this method invoke the logger in + #a backwards compatible way and router sub classes invoke + #it in non-backwards compatible ways if desired + $logger->$level_name($content, $metadata); +} + sub handle_log_request { my ($self, $metadata_in, $generator, @args) = @_; my %metadata = %{$metadata_in}; @@ -67,9 +79,9 @@ sub handle_log_request { @caller_info = caller($caller_level + 1); $metadata{method} = $caller_info[3]; $metadata{method} =~ s/^${package}::// if defined $metadata{method}; - + foreach my $logger ($self->_get_loggers(%metadata)) { - $logger->$level([ $generator->(@args) ], \%metadata); + $self->_invoke_logger($logger, $level, [ $generator->(@args) ], \%metadata); } }