diff --git a/lemonldap-ng-common/MANIFEST b/lemonldap-ng-common/MANIFEST index 632a60c40..4b8d840fb 100644 --- a/lemonldap-ng-common/MANIFEST +++ b/lemonldap-ng-common/MANIFEST @@ -37,6 +37,7 @@ lib/Lemonldap/NG/Common/Crypto.pm lib/Lemonldap/NG/Common/FormEncode.pm lib/Lemonldap/NG/Common/IPv6.pm lib/Lemonldap/NG/Common/Logger/Apache2.pm +lib/Lemonldap/NG/Common/Logger/Dispatch.pm lib/Lemonldap/NG/Common/Logger/Log4perl.pm lib/Lemonldap/NG/Common/Logger/Null.pm lib/Lemonldap/NG/Common/Logger/Sentry.pm diff --git a/lemonldap-ng-common/lib/Lemonldap/NG/Common/Logger/Dispatch.pm b/lemonldap-ng-common/lib/Lemonldap/NG/Common/Logger/Dispatch.pm new file mode 100644 index 000000000..47024514f --- /dev/null +++ b/lemonldap-ng-common/lib/Lemonldap/NG/Common/Logger/Dispatch.pm @@ -0,0 +1,41 @@ +package Lemonldap::NG::Common::Logger::Dispatch; + +use strict; + +our $VERSION = '2.0.0'; + +sub new { + no warnings 'redefine'; + my $self = bless {}, shift; + my ($conf) = @_; + my %bck; + my $last; + my $show = 1; + unless ( $conf->{logDispatchError} ) { + die 'At least, logDispatchError must be defined in conf'; + } + foreach my $l (qw(error warn notice info debug)) { + if ($show) { + $last = $conf->{ "logDispatch" . ucfirst($l) } || $last; + unless ( $bck{$last} ) { + eval "require $last"; + die $@ if ($@); + $bck{$last} = $last->new(@_); + } + my $obj = $bck{$last}; + eval "sub $l { + shift; + return \$obj->$l(\@_); + }"; + } + else { + eval qq'sub $l {1}'; + } + $show = 0 if ( $conf->{logLevel} eq $l ); + + } + die "unknown level $conf->{logLevel}" if ($show); + return $self; +} + +1;