Add Log4perl logger (closes: #1162)
This commit is contained in:
parent
e315a447d7
commit
c08489a6bc
|
@ -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]
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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]
|
||||
|
||||
|
|
|
@ -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;
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user