my @before_inc = grep { filter_not_core() } keys %mods;
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};
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
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(),
#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};
'%' => '%', 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},
};
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};
@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);
}
}