2014-03-13 16:07:36 +01:00
|
|
|
package Lemonldap::NG::Handler::Main::Logger;
|
|
|
|
|
2014-06-16 11:44:39 +02:00
|
|
|
use Lemonldap::NG::Handler::API qw( :httpCodes );
|
2014-03-13 16:07:36 +01:00
|
|
|
|
2014-07-24 17:48:32 +02:00
|
|
|
my $logLevel; # To control Lemonldap::NG logs: allows to overwrite
|
|
|
|
# log level defined in server config, or to set it
|
|
|
|
# if it can't be configured elsewhere (e.g. on CGIs)
|
|
|
|
my $logLevels = { # To compare log levels
|
2014-07-03 16:08:08 +02:00
|
|
|
emerg => 7,
|
|
|
|
alert => 6,
|
|
|
|
crit => 5,
|
|
|
|
error => 4,
|
|
|
|
warn => 3,
|
|
|
|
notice => 2,
|
|
|
|
info => 1,
|
|
|
|
debug => 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
BEGIN {
|
|
|
|
Lemonldap::NG::Handler::API->thread_share($logLevel);
|
|
|
|
Lemonldap::NG::Handler::API->thread_share($logLevels);
|
|
|
|
}
|
|
|
|
|
|
|
|
# @method void logLevelInit
|
|
|
|
# Set log level for Lemonldap::NG logs
|
|
|
|
sub logLevelInit {
|
|
|
|
my ( $class, $level ) = @_;
|
|
|
|
$logLevel = $level || $Lemonldap::NG::Handler::API::logLevel || "debug";
|
2015-05-14 08:44:38 +02:00
|
|
|
$logLevel = $logLevels->{$logLevel} || 0;
|
2014-07-03 16:08:08 +02:00
|
|
|
}
|
|
|
|
|
2014-07-01 14:58:04 +02:00
|
|
|
## @rmethod void lmLog(string msg, string level)
|
2014-03-13 16:07:36 +01:00
|
|
|
# Wrapper for Apache log system
|
2014-06-19 15:29:01 +02:00
|
|
|
# @param $msg message to log
|
|
|
|
# @param $level string (emerg|alert|crit|error|warn|notice|info|debug)
|
2014-03-13 16:07:36 +01:00
|
|
|
sub lmLog {
|
2014-07-01 14:58:04 +02:00
|
|
|
my ( $class, $msg, $level ) = @_;
|
2014-07-03 16:08:08 +02:00
|
|
|
return if ( $logLevels->{$level} < $logLevel );
|
|
|
|
|
2014-06-19 15:29:01 +02:00
|
|
|
my ( $module, $file, $line ) = caller();
|
|
|
|
|
|
|
|
if ( $level eq 'debug' ) {
|
|
|
|
$file =~ s#.+/##;
|
2014-07-01 14:58:04 +02:00
|
|
|
Lemonldap::NG::Handler::API->lmLog( "$file($line): $msg", "debug" );
|
2014-07-24 17:48:32 +02:00
|
|
|
}
|
|
|
|
else {
|
2014-07-03 17:20:20 +02:00
|
|
|
Lemonldap::NG::Handler::API->lmLog( "$file($line):", "debug" )
|
2014-07-24 17:48:32 +02:00
|
|
|
if ( $logLevel == 0 );
|
|
|
|
Lemonldap::NG::Handler::API->lmLog( "Lemonldap::NG::Handler: $msg",
|
|
|
|
$level );
|
2014-03-13 16:07:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|