package Log::Contextual::Role::Router;
+# ABSTRACT: Abstract interface between loggers and logging code blocks
+
use Moo::Role;
requires 'before_import';
__END__
-=head1 NAME
-
-Log::Contextual::Role::Router - Abstract interface between loggers and logging code blocks
-
=head1 SYNOPSIS
package MyApp::Log::Router;
-
+
use Moo;
use Log::Contextual::SimpleLogger;
-
+
with 'Log::Contextual::Role::Router';
-
+
has logger => (is => 'lazy');
-
+
sub _build_logger {
return Log::Contextual::SimpleLogger->new({ levels_upto => 'debug' });
}
-
+
sub before_import {
my ($self, %export_info) = @_;
my $exporter = $export_info{exporter};
my $log_level_name = $message_info{message_level};
my $logger = $self->logger;
my $is_active = $logger->can("is_${log_level_name}");
-
+
return unless defined $is_active && $logger->$is_active;
my $log_message = $log_code_block->(@$args);
$logger->$log_level_name($log_message);
use Moo;
use MyApp::Log::Router;
-
+
extends 'Log::Contextual';
#This example router is a singleton
use strict;
use warnings;
use MyApp::Log::Contextual qw(:log);
-
+
log_info { "Hello there" };
=head1 DESCRIPTION
=item arguments
-This is a hash reference containing the configuration values that were provided for the import.
+This is a hash reference containing the configuration values that were provided for the import.
The key is the name of the configuration item that was specified without the leading hyphen ('-').
For instance if the logging API is imported as follows
=item message_args
This is an array reference that contains the arguments given to the message generating code block.
-When invoking the message generator it will almost certainly be expecting these argument values
+When invoking the message generator it will almost certainly be expecting these argument values
as well.
=back
=back
-
-=head1 SEE ALSO
-
-=over 4
-
-=item C<Log::Contextual>
-
-=back
-
-