diff --git a/e2e-tests/lemonldap-ng.ini b/e2e-tests/lemonldap-ng.ini index 0ba9b2d4c..a01544aec 100644 --- a/e2e-tests/lemonldap-ng.ini +++ b/e2e-tests/lemonldap-ng.ini @@ -23,8 +23,8 @@ portalSkin = bootstrap staticPrefix = /static languages = fr, en templateDir = __pwd__/lemonldap-ng-portal/site/templates -u2fActivation = 1 -u2fSelfRegistration = 1 +;u2fActivation = 1 +;u2fSelfRegistration = 1 [handler] diff --git a/lemonldap-ng-common/MANIFEST b/lemonldap-ng-common/MANIFEST index 8ff7aad09..ccf5c92ba 100644 --- a/lemonldap-ng-common/MANIFEST +++ b/lemonldap-ng-common/MANIFEST @@ -34,6 +34,7 @@ lib/Lemonldap/NG/Common/Conf/Wrapper.pm lib/Lemonldap/NG/Common/Crypto.pm lib/Lemonldap/NG/Common/FormEncode.pm lib/Lemonldap/NG/Common/Logger/Apache2.pm +lib/Lemonldap/NG/Common/Logger/Log4perl.pm lib/Lemonldap/NG/Common/Logger/Std.pm lib/Lemonldap/NG/Common/Logger/Syslog.pm lib/Lemonldap/NG/Common/Module.pm diff --git a/lemonldap-ng-common/lemonldap-ng.ini b/lemonldap-ng-common/lemonldap-ng.ini index 0988fc787..e98f87b9e 100644 --- a/lemonldap-ng-common/lemonldap-ng.ini +++ b/lemonldap-ng-common/lemonldap-ng.ini @@ -43,25 +43,48 @@ logLevel = warn ; instead ; ; 2 - Change logger +; ; By default, logging is set to: -; - Lemonldap::NG::Common::Logger::Apache2 for ApacheMP2 handlers -; - Lemonldap::NG::Common::Logger::Syslog for FastCGI (Nginx) -; - Lemonldap::NG::Common::Logger::Std for PSGI applications (manager, -; portal,...) when they are not -; launched by FastCGI server -; Std is redirected to the web server logs for Apache. For Nginx, only if +; - Lemonldap::NG::Common::Logger::Apache2 for ApacheMP2 handlers +; - Lemonldap::NG::Common::Logger::Syslog for FastCGI (Nginx) +; - Lemonldap::NG::Common::Logger::Std for PSGI applications (manager, +; portal,...) when they are not +; launched by FastCGI server +; Other loggers availables: +; - Lemonldap::NG::Common::Logger::Log4perl to use Log4perl +; +; "Std" is redirected to the web server logs for Apache. For Nginx, only if ; request failed +; ; You can overload this in this section (for all) or in another section if -; you want to change logger for specified app. +; you want to change logger for a specified app. ; ; LLNG uses 2 loggers: 1 for technical logs (logger), 1 for user actions -; (userLogger) +; (userLogger). "userLogger" uses the same class as "logger" if not set. ;logger = Lemonldap::NG::Common::Logger::Syslog -;userLogger = Lemonldap::NG::Common::Logger::Syslog +;userLogger = Lemonldap::NG::Common::Logger::Log4perl ; -; For Syslog logging, you can also overwrite facilities. Default values: +; 2.1 - Using Syslog +; +; For Syslog logging, you can also overwrite facilities. Default values: +;logger = Lemonldap::NG::Common::Logger::Syslog ;syslogFacility = daemon ;userSyslogFacility = auth +; +; 2.2 - Using Log4perl +; +; If you want to use Log4perl, you can set these parameters. Here are default +; values: +;logger = Lemonldap::NG::Common::Logger::Log4perl +;log4perlConfFile = /etc/log4perl.conf +;log4perlLogger = LLNG +;log4perlUserLogger = LLNG.user +; +; Here, Log4perl configuration is read from /etc/log4perl.conf. The "LLNG" +; value points to the logger class. Example: +; log4perl.logger.LLNG = WARN, File1 +; log4perl.logger.LLNG.user = INFO, File2 +; ... [configuration] diff --git a/lemonldap-ng-common/lib/Lemonldap/NG/Common/Logger/Log4perl.pm b/lemonldap-ng-common/lib/Lemonldap/NG/Common/Logger/Log4perl.pm new file mode 100644 index 000000000..a7beca318 --- /dev/null +++ b/lemonldap-ng-common/lib/Lemonldap/NG/Common/Logger/Log4perl.pm @@ -0,0 +1,33 @@ +package Lemonldap::NG::Common::Logger::Log4perl; + +use strict; +use Log::Log4perl; +use Mouse; + +our $init = 0; + +sub new { + my ( $class, $conf, %args ) = @_; + my $self = bless {}, $class; + unless ($init) { + my $file = $conf->{log4perlConfFile} || '/etc/log4perl.conf'; + Log::Log4perl->init($file); + $init++; + } + my $logger = + $args{user} + ? ( $conf->{log4perlUserLogger} || 'LLNG.user' ) + : ( $conf->{log4perlLogger} || 'LLNG' ); + $self->{log} = Log::Log4perl->get_logger($logger); + return $self; +} + +sub AUTOLOAD { + my $self = shift; + no strict; + $AUTOLOAD =~ s/.*:://; + $AUTOLOAD =~ s/notice/info/; + return $self->{log}->$AUTOLOAD(@_); +} + +1; diff --git a/lemonldap-ng-handler/lib/Lemonldap/NG/Handler/Main/Init.pm b/lemonldap-ng-handler/lib/Lemonldap/NG/Handler/Main/Init.pm index b7df60609..0784c2ee2 100644 --- a/lemonldap-ng-handler/lib/Lemonldap/NG/Handler/Main/Init.pm +++ b/lemonldap-ng-handler/lib/Lemonldap/NG/Handler/Main/Init.pm @@ -52,10 +52,12 @@ sub logLevelInit { eval "require $logger"; die $@ if ($@); $class->logger( $logger->new( $class->localConfig ) ); + $class->logger->debug("Logger $logger loaded"); $logger = $class->localConfig->{userLogger} || $logger; eval "require $logger"; die $@ if ($@); $class->userLogger( $logger->new( $class->localConfig ), user => 1 ); + $class->logger->debug("User logger $logger loaded"); } # @method void serverSignatureInit diff --git a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager.pm b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager.pm index 6683957dd..d664f908d 100644 --- a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager.pm +++ b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager.pm @@ -32,8 +32,10 @@ sub init { $args ||= {}; if ( my $localconf = $self->confAcc->getLocalConf(MANAGERSECTION) ) { - $self->{$_} = $args->{$_} //= $localconf->{$_} - foreach ( grep { $_ !~ /^(?:l|userL)ogger$/ } keys %$localconf ); + foreach ( keys %$localconf ) { + $args->{$_} //= $localconf->{$_}; + $self->{$_} = $args->{$_} unless(/^(?:l|userL)ogger$/); + } } # Manager needs to keep new Ajax behaviour