Commit deb28bc9 authored by Yadd's avatar Yadd

Replace lmLog by logger-> (#857)

parent b7d4dac6
...@@ -35,6 +35,7 @@ lib/Lemonldap/NG/Common/Crypto.pm ...@@ -35,6 +35,7 @@ lib/Lemonldap/NG/Common/Crypto.pm
lib/Lemonldap/NG/Common/FormEncode.pm lib/Lemonldap/NG/Common/FormEncode.pm
lib/Lemonldap/NG/Common/Logger/Apache2.pm lib/Lemonldap/NG/Common/Logger/Apache2.pm
lib/Lemonldap/NG/Common/Logger/Std.pm lib/Lemonldap/NG/Common/Logger/Std.pm
lib/Lemonldap/NG/Common/Logger/Syslog.pm
lib/Lemonldap/NG/Common/Module.pm lib/Lemonldap/NG/Common/Module.pm
lib/Lemonldap/NG/Common/Notifications.pm lib/Lemonldap/NG/Common/Notifications.pm
lib/Lemonldap/NG/Common/Notifications/DBI.pm lib/Lemonldap/NG/Common/Notifications/DBI.pm
......
...@@ -173,7 +173,7 @@ sub getConf { ...@@ -173,7 +173,7 @@ sub getConf {
unless ( ref( $self->{refLocalStorage} ) ) { unless ( ref( $self->{refLocalStorage} ) ) {
$msg .= "Get remote configuration (localStorage unavailable).\n"; $msg .= "Get remote configuration (localStorage unavailable).\n";
$r = $self->getDBConf($args); $r = $self->getDBConf($args);
return undef unless ($r->{cfgNum}); return undef unless ( $r->{cfgNum} );
$self->setDefault( $r, $args->{localPrm} ); $self->setDefault( $r, $args->{localPrm} );
$self->compactConf($r); $self->compactConf($r);
} }
......
...@@ -96,14 +96,14 @@ sub store { ...@@ -96,14 +96,14 @@ sub store {
sub load { sub load {
my ( $self, $cfgNum, $fields ) = @_; my ( $self, $cfgNum, $fields ) = @_;
my ($f,$filename); my ( $f, $filename );
if ( -e $self->_file($cfgNum) ) { if ( -e $self->_file($cfgNum) ) {
$filename = $self->_file($cfgNum); $filename = $self->_file($cfgNum);
} }
elsif ( -e "$self->{dirName}/lmConf-$cfgNum.js" ) { elsif ( -e "$self->{dirName}/lmConf-$cfgNum.js" ) {
$filename = "$self->{dirName}/lmConf-$cfgNum.js"; $filename = "$self->{dirName}/lmConf-$cfgNum.js";
} }
if($filename) { if ($filename) {
local $/ = ''; local $/ = '';
my $ret; my $ret;
unless ( open FILE, $filename ) { unless ( open FILE, $filename ) {
......
...@@ -18,7 +18,7 @@ sub compactConf { ...@@ -18,7 +18,7 @@ sub compactConf {
$keep{$mod} = 1; $keep{$mod} = 1;
} }
if ( $keep{combination} ) { if ( $keep{combination} ) {
foreach my $md (keys %{$conf->{combModules}}) { foreach my $md ( keys %{ $conf->{combModules} } ) {
$_ = $conf->{combModules}->{$md}->{type}; $_ = $conf->{combModules}->{$md}->{type};
s/^(\w+).*$/lc($1)/e; s/^(\w+).*$/lc($1)/e;
s/OpenIDConnect/oidc/i; s/OpenIDConnect/oidc/i;
...@@ -35,7 +35,7 @@ sub compactConf { ...@@ -35,7 +35,7 @@ sub compactConf {
} }
} }
} }
foreach my $key (keys %$authParameters) { foreach my $key ( keys %$authParameters ) {
my $mod = $key; my $mod = $key;
$mod =~ s/Params$//; $mod =~ s/Params$//;
unless ( $keep{$mod} ) { unless ( $keep{$mod} ) {
......
...@@ -28,14 +28,14 @@ extends 'Lemonldap::NG::Common::Conf::AccessLib'; ...@@ -28,14 +28,14 @@ extends 'Lemonldap::NG::Common::Conf::AccessLib';
#@return keyvalue (string, int or hashref) #@return keyvalue (string, int or hashref)
sub getConfKey { sub getConfKey {
my ( $self, $req, $key, @args ) = @_; my ( $self, $req, $key, @args ) = @_;
$self->lmLog( "Search for $key in conf", 'debug' ); $self->logger->debug("Search for $key in conf");
# Verify that cfgNum has been asked # Verify that cfgNum has been asked
unless ( defined $req->params('cfgNum') ) { unless ( defined $req->params('cfgNum') ) {
$req->error("Missing configuration number"); $req->error("Missing configuration number");
return undef; return undef;
} }
$self->lmLog( "Cfgnum set to " . $req->params('cfgNum'), 'debug' ); $self->logger->debug( "Cfgnum set to " . $req->params('cfgNum') );
# when 'latest' => replace by last cfgNum # when 'latest' => replace by last cfgNum
if ( $req->params('cfgNum') eq 'latest' ) { if ( $req->params('cfgNum') eq 'latest' ) {
...@@ -117,7 +117,7 @@ sub getConfByNum { ...@@ -117,7 +117,7 @@ sub getConfByNum {
#@return PSGI JSON response #@return PSGI JSON response
sub complexNodesRoot { sub complexNodesRoot {
my ( $self, $req, $query, $tpl ) = @_; my ( $self, $req, $query, $tpl ) = @_;
$self->lmLog( "Query for $query template keys", 'debug' ); $self->logger->debug("Query for $query template keys");
my $tmp = $self->getConfKey( $req, $query ); my $tmp = $self->getConfKey( $req, $query );
return $self->sendError( $req, undef, 400 ) if ( $req->error ); return $self->sendError( $req, undef, 400 ) if ( $req->error );
...@@ -170,7 +170,7 @@ sub virtualHosts { ...@@ -170,7 +170,7 @@ sub virtualHosts {
my ( $id, $resp ) = ( 1, [] ); my ( $id, $resp ) = ( 1, [] );
my $vhk = eval { $self->getConfKey( $req, $query )->{$vh} } // {}; my $vhk = eval { $self->getConfKey( $req, $query )->{$vh} } // {};
return $self->sendError( $req, undef, 400 ) if ( $req->error ); return $self->sendError( $req, undef, 400 ) if ( $req->error );
$self->lmLog( "Query for $vh/$query keys", 'debug' ); $self->logger->debug("Query for $vh/$query keys");
# Keys are ordered except 'default' which must be at the end # Keys are ordered except 'default' which must be at the end
foreach my $r ( foreach my $r (
...@@ -210,7 +210,7 @@ sub virtualHosts { ...@@ -210,7 +210,7 @@ sub virtualHosts {
return $self->sendJSONresponse( $req, $resp ); return $self->sendJSONresponse( $req, $resp );
} }
elsif ( $query =~ /^vhost(?:(?:Aliase|Http)s|Maintenance|Port|Type)$/ ) { elsif ( $query =~ /^vhost(?:(?:Aliase|Http)s|Maintenance|Port|Type)$/ ) {
$self->lmLog( "Query for $vh/$query key", 'debug' ); $self->logger->debug("Query for $vh/$query key");
# TODO: verify how this is done actually # TODO: verify how this is done actually
my $k1 = $self->getConfKey( $req, 'vhostOptions' ); my $k1 = $self->getConfKey( $req, 'vhostOptions' );
...@@ -593,14 +593,14 @@ sub combModules { ...@@ -593,14 +593,14 @@ sub combModules {
foreach my $mod ( keys %$val ) { foreach my $mod ( keys %$val ) {
my $tmp; my $tmp;
$tmp->{title} = $mod; $tmp->{title} = $mod;
$tmp->{id} = "combModules/$mod"; $tmp->{id} = "combModules/$mod";
$tmp->{type} = 'cmbModule'; $tmp->{type} = 'cmbModule';
$tmp->{data}->{$_} = $val->{$mod}->{$_} foreach (qw(type for)); $tmp->{data}->{$_} = $val->{$mod}->{$_} foreach (qw(type for));
my $over = $val->{$mod}->{over} // {}; my $over = $val->{$mod}->{over} // {};
$tmp->{data}->{over} = [ map { [ $_, $over->{$_} ] } keys %$over ]; $tmp->{data}->{over} = [ map { [ $_, $over->{$_} ] } keys %$over ];
push @$res, $tmp; push @$res, $tmp;
} }
return $self->sendJSONresponse($req,$res); return $self->sendJSONresponse( $req, $res );
} }
# 33 - Root queries # 33 - Root queries
......
...@@ -2,7 +2,7 @@ package Lemonldap::NG::Common::Logger::Apache2; ...@@ -2,7 +2,7 @@ package Lemonldap::NG::Common::Logger::Apache2;
use Apache2::ServerRec; use Apache2::ServerRec;
sub new{ sub new {
return bless {}, shift; return bless {}, shift;
} }
...@@ -10,6 +10,6 @@ sub AUTOLOAD { ...@@ -10,6 +10,6 @@ sub AUTOLOAD {
shift; shift;
$AUTOLOAD =~ s/.*:://; $AUTOLOAD =~ s/.*:://;
return Apache2::ServerRec->log->$AUTOLOAD(@_); return Apache2::ServerRec->log->$AUTOLOAD(@_);
}; }
1; 1;
...@@ -22,7 +22,7 @@ sub new { ...@@ -22,7 +22,7 @@ sub new {
$name = 'warning' if ( $_ eq 'warn' ); $name = 'warning' if ( $_ eq 'warn' );
$name = 'err' if ( $_ eq 'error' ); $name = 'err' if ( $_ eq 'error' );
eval qq'sub $_ {syslog("$name|".\$_[0]->{facility},\$_[1])}'; eval qq'sub $_ {syslog("$name|".\$_[0]->{facility},\$_[1])}';
die $@ if($@); die $@ if ($@);
} }
else { else {
eval qq'sub $_ {1}'; eval qq'sub $_ {1}';
......
...@@ -5,16 +5,14 @@ use Mouse; ...@@ -5,16 +5,14 @@ use Mouse;
our $VERSION = '2.0.0'; our $VERSION = '2.0.0';
# Object that provides lmLog and error methods (typically PSGI object) # Object that provides loggers and error methods (typically PSGI object)
has p => ( is => 'rw', weak_ref => 1 ); has p => ( is => 'rw', weak_ref => 1 );
# Lemonldap::NG configuration hash ref # Lemonldap::NG configuration hash ref
has conf => ( is => 'rw', weak_ref => 1 ); has conf => ( is => 'rw', weak_ref => 1 );
sub lmLog { has logger => ( is => 'ro', default => sub { $_[0]->{p}->logger } );
my $self = shift; has userLogger => ( is => 'ro', default => sub { $_[0]->{p}->userLogger } );
return $self->p->lmLog(@_);
}
sub error { sub error {
my $self = shift; my $self = shift;
......
...@@ -14,9 +14,10 @@ use Encode; ...@@ -14,9 +14,10 @@ use Encode;
our $VERSION = '2.0.0'; our $VERSION = '2.0.0';
extends 'Lemonldap::NG::Common::Notifications'; extends 'Lemonldap::NG::Common::Notifications';
sub import { sub import {
shift; shift;
return Lemonldap::NG::Common::Notifications->import(@_) return Lemonldap::NG::Common::Notifications->import(@_);
} }
has dbiTable => ( has dbiTable => (
...@@ -32,7 +33,7 @@ has dbiChain => ( ...@@ -32,7 +33,7 @@ has dbiChain => (
has dbiUser => ( has dbiUser => (
is => 'ro', is => 'ro',
default => sub { default => sub {
$_[0]->{p}->lmLog( 'Warning: "dbiUser" parameter is not set', 'warn' ); $_[0]->{p}->logger->warn('Warning: "dbiUser" parameter is not set');
return ''; return '';
} }
); );
...@@ -49,7 +50,7 @@ has _dbh => ( ...@@ -49,7 +50,7 @@ has _dbh => (
$self->{dbiChain}, $self->{dbiUser}, $self->{dbiChain}, $self->{dbiUser},
$self->{dbiPassword}, { RaiseError => 0 } $self->{dbiPassword}, { RaiseError => 0 }
); );
$self->lmLog( $DBI::errstr, 'error' ) unless ($r); $self->logger->error($DBI::errstr) unless ($r);
return $r; return $r;
} }
); );
...@@ -83,7 +84,7 @@ sub get { ...@@ -83,7 +84,7 @@ sub get {
&getIdentifier( $self, $h->{uid}, $h->{ref}, $h->{date} ); &getIdentifier( $self, $h->{uid}, $h->{ref}, $h->{date} );
$result->{$identifier} = $xml; $result->{$identifier} = $xml;
} }
$self->lmLog( $self->sth->err(), 'warn' ) if ( $self->sth->err() ); $self->logger->warn( $self->sth->err() ) if ( $self->sth->err() );
return $result; return $result;
} }
...@@ -104,7 +105,7 @@ sub getAll { ...@@ -104,7 +105,7 @@ sub getAll {
condition => $h->{condition} condition => $h->{condition}
}; };
} }
$self->lmLog( $self->sth->err(), 'warn' ) if ( $self->sth->err() ); $self->logger->warn( $self->sth->err() ) if ( $self->sth->err() );
return $result; return $result;
} }
...@@ -115,7 +116,7 @@ sub delete { ...@@ -115,7 +116,7 @@ sub delete {
my ( $self, $myref ) = @_; my ( $self, $myref ) = @_;
my ( $d, $u, $r ); my ( $d, $u, $r );
unless ( ( $d, $u, $r ) = ( $myref =~ /^([^#]+)#(.+?)#(.+)$/ ) ) { unless ( ( $d, $u, $r ) = ( $myref =~ /^([^#]+)#(.+?)#(.+)$/ ) ) {
$self->lmLog( "Bad reference $myref", 'warn' ); $self->logger->warn("Bad reference $myref");
return 0; return 0;
} }
my @ts = localtime(); my @ts = localtime();
...@@ -136,7 +137,7 @@ sub purge { ...@@ -136,7 +137,7 @@ sub purge {
my ( $self, $myref, $force ) = @_; my ( $self, $myref, $force ) = @_;
my ( $d, $u, $r ); my ( $d, $u, $r );
unless ( ( $d, $u, $r ) = ( $myref =~ /^([^#]+)#(.+?)#(.+)$/ ) ) { unless ( ( $d, $u, $r ) = ( $myref =~ /^([^#]+)#(.+?)#(.+)$/ ) ) {
$self->lmLog( "Bad reference $myref", 'warn' ); $self->logger->warn("Bad reference $myref");
return 0; return 0;
} }
...@@ -186,7 +187,7 @@ sub getDone { ...@@ -186,7 +187,7 @@ sub getDone {
$result->{"$h->{date}#$h->{uid}#$h->{ref}"} = $result->{"$h->{date}#$h->{uid}#$h->{ref}"} =
{ notified => $done, uid => $h->{uid}, ref => $h->{ref}, }; { notified => $done, uid => $h->{uid}, ref => $h->{ref}, };
} }
$self->lmLog( $self->sth->err(), 'warn' ) if ( $self->sth->err() ); $self->logger->warn( $self->sth->err() ) if ( $self->sth->err() );
return $result; return $result;
} }
...@@ -197,12 +198,12 @@ sub _execute { ...@@ -197,12 +198,12 @@ sub _execute {
my ( $self, $query, @args ) = @_; my ( $self, $query, @args ) = @_;
my $dbh = $self->_dbh or return 0; my $dbh = $self->_dbh or return 0;
unless ( $self->sth( $dbh->prepare($query) ) ) { unless ( $self->sth( $dbh->prepare($query) ) ) {
$self->lmLog( $dbh->errstr(), 'warn' ); $self->logger->warn( $dbh->errstr() );
return 0; return 0;
} }
my $tmp; my $tmp;
unless ( $tmp = $self->sth->execute(@args) ) { unless ( $tmp = $self->sth->execute(@args) ) {
$self->lmLog( $self->sth->errstr(), 'warn' ); $self->logger->warn( $self->sth->errstr() );
return 0; return 0;
} }
return $tmp; return $tmp;
......
...@@ -48,8 +48,8 @@ sub get { ...@@ -48,8 +48,8 @@ sub get {
my $files; my $files;
foreach my $file (@notif) { foreach my $file (@notif) {
unless ( open F, $self->{dirName} . "/$file" ) { unless ( open F, $self->{dirName} . "/$file" ) {
$self->lmLog( "Unable to read notification $self->{dirName}/$file", $self->logger->error(
'error' ); "Unable to read notification $self->{dirName}/$file");
next; next;
} }
$files->{$file} = join( '', <F> ); $files->{$file} = join( '', <F> );
......
...@@ -9,7 +9,7 @@ sub newNotification { ...@@ -9,7 +9,7 @@ sub newNotification {
my $json; my $json;
eval { $json = from_json($jsonString) }; eval { $json = from_json($jsonString) };
if ( my $err = $@ ) { if ( my $err = $@ ) {
eval { $self->lmLog( "Unable to decode JSON file: $err", 'error' ) }; eval { $self->logger->error("Unable to decode JSON file: $err") };
return 0; return 0;
} }
my @notifs; my @notifs;
...@@ -21,7 +21,7 @@ sub newNotification { ...@@ -21,7 +21,7 @@ sub newNotification {
foreach (qw(date uid reference)) { foreach (qw(date uid reference)) {
my $tmp; my $tmp;
unless ( $tmp = $notif->{$_} ) { unless ( $tmp = $notif->{$_} ) {
$self->lmLog( "Attribute $_ is missing", 'error' ); $self->logger->error("Attribute $_ is missing");
return 0; return 0;
} }
push @datas, $tmp; push @datas, $tmp;
...@@ -44,16 +44,14 @@ sub deleteNotification { ...@@ -44,16 +44,14 @@ sub deleteNotification {
# Check input parameters # Check input parameters
unless ( $uid and $myref ) { unless ( $uid and $myref ) {
$self->lmLog( $self->userLogger->error(
'REST service "delete notification" called without all parameters', 'REST service "delete notification" called without all parameters'
'error'
); );
return 0; return 0;
} }
$self->lmLog( $self->logger->debug(
"REST service deleteNotification called for uid $uid and reference $myref", "REST service deleteNotification called for uid $uid and reference $myref"
'debug'
); );
# Get notifications # Get notifications
...@@ -79,7 +77,7 @@ sub deleteNotification { ...@@ -79,7 +77,7 @@ sub deleteNotification {
# Delete the notification (really) # Delete the notification (really)
foreach (@data) { foreach (@data) {
if ( $self->purge( $_, 1 ) ) { if ( $self->purge( $_, 1 ) ) {
$self->lmLog( "Notification $_ was removed.", 'debug' ); $self->logger->debug("Notification $_ was removed.");
$count++; $count++;
} }
} }
......
...@@ -16,9 +16,10 @@ use utf8; ...@@ -16,9 +16,10 @@ use utf8;
our $VERSION = '2.0.0'; our $VERSION = '2.0.0';
extends 'Lemonldap::NG::Common::Notifications'; extends 'Lemonldap::NG::Common::Notifications';
sub import { sub import {
shift; shift;
return Lemonldap::NG::Common::Notifications->import(@_) return Lemonldap::NG::Common::Notifications->import(@_);
} }
has ldapServer => ( has ldapServer => (
...@@ -38,7 +39,7 @@ has ldapConfBase => ( ...@@ -38,7 +39,7 @@ has ldapConfBase => (
has ldapBindDN => ( has ldapBindDN => (
is => 'ro', is => 'ro',
default => sub { default => sub {
$_[0]->p->lmLog( 'Warning: "ldapBindDN" parameter is not set', 'warn' ); $_[0]->p->logger->warn('Warning: "ldapBindDN" parameter is not set');
return ''; return '';
} }
); );
...@@ -69,7 +70,7 @@ sub get { ...@@ -69,7 +70,7 @@ sub get {
my $identifier = my $identifier =
&getIdentifier( $self, $f->{uid}, $f->{ref}, $f->{date} ); &getIdentifier( $self, $f->{uid}, $f->{ref}, $f->{date} );
$result->{$identifier} = "$xml"; $result->{$identifier} = "$xml";
$self->lmLog( "notification $identifier found", 'info' ); $self->logger->info("notification $identifier found");
} }
return $result; return $result;
...@@ -113,7 +114,7 @@ sub delete { ...@@ -113,7 +114,7 @@ sub delete {
my ( $self, $myref ) = @_; my ( $self, $myref ) = @_;
my ( $d, $u, $r ); my ( $d, $u, $r );
unless ( ( $d, $u, $r ) = ( $myref =~ /^([^#]+)#(.+?)#(.+)$/ ) ) { unless ( ( $d, $u, $r ) = ( $myref =~ /^([^#]+)#(.+?)#(.+)$/ ) ) {
$self->lmLog( "Bad reference $myref", 'warn' );