caller_level => 1,
level => $level,
}, $code) };
- warn "could not deliver log event during Flog_$level: $@" if defined $@;
+ warn "could not deliver log event during Flog_$level: $@" if $@;
eval { carp $code->() };
- warn "could not emit warning during Flog_$level: $@" if defined $@;
+ warn "could not emit warning during Flog_$level: $@" if $@;
exit($exit_value);
});
}
my $format = $ENV{OBJECT_REMOTE_LOG_FORMAT};
my $selections = $ENV{OBJECT_REMOTE_LOG_SELECTIONS};
my %controller_should_log;
-
+
+ eval {
+ require Log::Any::Adapter;
+ require Object::Remote::Logging::LogAnyInjector;
+ Log::Any::Adapter->set('+Object::Remote::Logging::LogAnyInjector');
+ };
+
return unless defined $level;
$format = "[%l %r] %s" unless defined $format;
$selections = __PACKAGE__ unless defined $selections;
--- /dev/null
+package Object::Remote::Logging::LogAnyInjector;
+
+use Moo;
+use Object::Remote::Logging qw( router );
+use Carp qw(croak);
+
+BEGIN {
+ our %LEVEL_NAME_MAP = (
+ #key is Log::Any log level name or alias and value is Object::Remote::Logging
+ #log level name
+ trace => 'trace', debug => 'debug', info => 'info', notice => 'verbose',
+ warning => 'warn', error => 'error', fatal => 'fatal',
+ critical => 'error', alert => 'error', 'emergency' => 'error',
+ inform => 'info', warn => 'warn', err => 'error', crit => 'error',
+ );
+}
+
+sub AUTOLOAD {
+ my ($self, @content) = @_;
+ (my $log_level) = (our $AUTOLOAD =~ /([^:]+)$/);
+ my $generator;
+ my $log_contextual_level;
+ our %LEVEL_NAME_MAP;
+
+ #just a proof of concept - support for the is_ methods can
+ #be done but requires more modifications to the router
+ return 1 if $log_level =~ m/^is_/;
+ #skip DESTROY and friends
+ return if $log_level =~ m/^[A-Z]+$/;
+
+ if ($log_level =~ s/f$//) {
+ my $format = shift(@content);
+ $generator = sub { sprintf($format, @content) };
+ } else {
+ $generator = sub { @content };
+ }
+
+ $log_contextual_level = $LEVEL_NAME_MAP{$log_level};
+ croak "invalid log level name: $log_level" unless defined $log_contextual_level;
+
+ router->handle_log_request({
+ controller => 'Log::Any',
+ package => scalar(caller),
+ caller_level => 1,
+ level => $log_contextual_level,
+ }, $generator);
+
+ return;
+}
+
+1;