| 1 |
package Lemonldap::NG::Common::Logger::Dispatch; |
| 2 |
|
| 3 |
use strict; |
| 4 |
|
| 5 |
our $VERSION = '2.0.15'; |
| 6 |
|
| 7 |
sub new { |
| 8 |
no warnings 'redefine'; |
| 9 |
my $self = bless {}, shift; |
| 10 |
my ( $conf, %args ) = @_; |
| 11 |
my ( %bck, $last ); |
| 12 |
my $root = $args{user} ? 'userLogDispatch' : 'logDispatch'; |
| 13 |
my $show = 1; |
| 14 |
die "At least, ${root}Error must be defined in conf" |
| 15 |
unless ( $conf->{ $root . 'Error' } ); |
| 16 |
|
| 17 |
foreach my $l (qw(error warn notice info debug)) { |
| 18 |
if ($show) { |
| 19 |
$last = $conf->{ $root . ucfirst($l) } || $last; |
| 20 |
unless ( $bck{$last} ) { |
| 21 |
eval "require $last"; |
| 22 |
die $@ if ($@); |
| 23 |
$bck{$last} = $last->new(@_); |
| 24 |
} |
| 25 |
my $obj = $bck{$last}; |
| 26 |
eval "sub $l { |
| 27 |
shift; |
| 28 |
return \$obj->$l(\@_); |
| 29 |
}"; |
| 30 |
} |
| 31 |
else { |
| 32 |
eval qq'sub $l {1}'; |
| 33 |
} |
| 34 |
$show = 0 if ( $conf->{logLevel} eq $l ); |
| 35 |
} |
| 36 |
die "Unknown logLevel $conf->{logLevel}" if $show; |
| 37 |
|
| 38 |
return $self; |
| 39 |
} |
| 40 |
|
| 41 |
1; |