/usr/share/perl5/Log/Contextual/Router.pm is in liblog-contextual-perl 0.006004-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | package Log::Contextual::Router;
$Log::Contextual::Router::VERSION = '0.006004';
# ABSTRACT: Route messages to loggers
use Moo;
use Scalar::Util 'blessed';
with 'Log::Contextual::Role::Router',
'Log::Contextual::Role::Router::SetLogger',
'Log::Contextual::Role::Router::WithLogger';
eval {
require Log::Log4perl;
die if $Log::Log4perl::VERSION < 1.29;
Log::Log4perl->wrapper_register(__PACKAGE__)
};
has _default_logger => (
is => 'ro',
default => sub { {} },
init_arg => undef,
);
has _package_logger => (
is => 'ro',
default => sub { {} },
init_arg => undef,
);
has _get_logger => (
is => 'ro',
default => sub { {} },
init_arg => undef,
);
sub before_import { }
sub after_import {
my ($self, %import_info) = @_;
my $exporter = $import_info{exporter};
my $target = $import_info{target};
my $config = $import_info{arguments};
if (my $l = $exporter->arg_logger($config->{logger})) {
$self->set_logger($l);
}
if (my $l = $exporter->arg_package_logger($config->{package_logger})) {
$self->_set_package_logger_for($target, $l);
}
if (my $l = $exporter->arg_default_logger($config->{default_logger})) {
$self->_set_default_logger_for($target, $l);
}
}
sub with_logger {
my $logger = $_[1];
if (ref $logger ne 'CODE') {
die 'logger was not a CodeRef or a logger object. Please try again.'
unless blessed($logger);
$logger = do {
my $l = $logger;
sub { $l }
}
}
local $_[0]->_get_logger->{l} = $logger;
$_[2]->();
}
sub set_logger {
my $logger = $_[1];
if (ref $logger ne 'CODE') {
die 'logger was not a CodeRef or a logger object. Please try again.'
unless blessed($logger);
$logger = do {
my $l = $logger;
sub { $l }
}
}
warn 'set_logger (or -logger) called more than once! This is a bad idea!'
if $_[0]->_get_logger->{l};
$_[0]->_get_logger->{l} = $logger;
}
sub _set_default_logger_for {
my $logger = $_[2];
if (ref $logger ne 'CODE') {
die 'logger was not a CodeRef or a logger object. Please try again.'
unless blessed($logger);
$logger = do {
my $l = $logger;
sub { $l }
}
}
$_[0]->_default_logger->{$_[1]} = $logger
}
sub _set_package_logger_for {
my $logger = $_[2];
if (ref $logger ne 'CODE') {
die 'logger was not a CodeRef or a logger object. Please try again.'
unless blessed($logger);
$logger = do {
my $l = $logger;
sub { $l }
}
}
$_[0]->_package_logger->{$_[1]} = $logger
}
sub get_loggers {
my ($self, %info) = @_;
my $package = $info{caller_package};
my $log_level = $info{message_level};
my $logger =
( $_[0]->_package_logger->{$package}
|| $_[0]->_get_logger->{l}
|| $_[0]->_default_logger->{$package}
|| die
q( no logger set! you can't try to log something without a logger! ));
$info{caller_level}++;
$logger = $logger->($package, \%info);
return $logger if $logger ->${\"is_${log_level}"};
return ();
}
sub handle_log_request {
my ($self, %message_info) = @_;
my $generator = $message_info{message_sub};
my $args = $message_info{message_args};
my $log_level = $message_info{message_level};
$message_info{caller_level}++;
foreach my $logger ($self->get_loggers(%message_info)) {
$logger->$log_level($generator->(@$args));
}
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Log::Contextual::Router - Route messages to loggers
=head1 VERSION
version 0.006004
=head1 AUTHOR
Arthur Axel "fREW" Schmidt <frioux+cpan@gmail.com>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2014 by Arthur Axel "fREW" Schmidt.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
|