Revision history for {{$dist->name}}
{{$NEXT}}
+ - Modernize usage of Log::Contextual, creating a simple example for how to
+ make static loggers for modules and applications
0.002206 2013-03-09 12:50:57 CST6CDT
- Fix embarrassing broken charity link
parent = 0.225
autodie = 0
namespace::autoclean = 0
-Log::Contextual = 0.004200
+Log::Contextual = 0.005005
Path::Class = 0.26
DBIx::Class = 0.08121
Moose = 1.0
+Moo = 1.003000
MooseX::Role::Parameterized = 0.18
Try::Tiny = 0
SQL::Translator = 0.11005
use parent 'Log::Contextual';
-use DBIx::Class::DeploymentHandler::Logger;
+use DBIx::Class::DeploymentHandler::LogRouter;
-my $logger = DBIx::Class::DeploymentHandler::Logger->new({
- env_prefix => 'DBICDH'
-});
-
-sub arg_package_logger { $_[1] || $logger }
+{
+ my $router;
+ sub router { $router ||= DBIx::Class::DeploymentHandler::LogRouter->new }
+}
1;
--- /dev/null
+package DBIx::Class::DeploymentHandler::LogRouter;
+use Moo;
+use DBIx::Class::DeploymentHandler::Logger;
+
+with 'Log::Contextual::Role::Router';
+
+has _logger => (
+ is => 'lazy',
+ builder => sub { DBIx::Class::DeploymentHandler::Logger->new },
+);
+
+sub handle_log_request {
+ my ($self, %message_info) = @_;
+
+ my $log_code_block = $message_info{message_sub};
+ my $args = $message_info{message_args};
+ 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);
+
+ $self->_logger->$log_level_name($log_message);
+}
+
+sub before_import {}
+sub after_import {}
+
+1;
warn "[DBICDH] [$level] $message";
}
+sub new {
+ my ($self, $options, @rest) = @_;
+
+ $options ||= {};
+ $options->{env_prefix} ||= 'DBICDH';
+
+ $self->next::method($options, @rest)
+}
+
1;