diff --git a/en.dict.combodo-saml.php b/en.dict.combodo-saml.php index fa58667..407e164 100644 --- a/en.dict.combodo-saml.php +++ b/en.dict.combodo-saml.php @@ -11,7 +11,7 @@ Dict::Add('EN US', 'English', 'English', array( 'SAML:Error:UserNotAllowed' => 'User not allowed', 'SAML:Error:ErrorOccurred' => 'An error occurred', - 'SAML:Error:CheckTheLogFileForMoreInformation' => 'Check the log file "log/saml.log" for more information.', + 'SAML:Error:CheckTheLogFileForMoreInformation' => 'Check the log file for more information.', 'SAML:Error:NotAuthenticated' => 'Not authenticated', 'SAML:SimpleSaml:GenerateSimpleSamlConf' => 'Generate configuration for SimpleSaml', 'SAML:SimpleSaml:Instructions' => 'Append this conf to: simplesamlphp/metadata/saml20-sp-remote.php', diff --git a/en_gb.dict.combodo-saml.php b/en_gb.dict.combodo-saml.php index da8dd5b..f6f97fc 100644 --- a/en_gb.dict.combodo-saml.php +++ b/en_gb.dict.combodo-saml.php @@ -11,7 +11,7 @@ Dict::Add('EN GB', 'British English', 'British English', array( 'SAML:Error:UserNotAllowed' => 'User not allowed', 'SAML:Error:ErrorOccurred' => 'An error occurred', - 'SAML:Error:CheckTheLogFileForMoreInformation' => 'Check the log file "log/saml.log" for more information.', + 'SAML:Error:CheckTheLogFileForMoreInformation' => 'Check the log file for more information.', 'SAML:Error:NotAuthenticated' => 'Not authenticated', 'SAML:SimpleSaml:GenerateSimpleSamlConf' => 'Generate configuration for SimpleSaml', 'SAML:SimpleSaml:Instructions' => 'Append this conf to: simplesamlphp/metadata/saml20-sp-remote.php', diff --git a/fr.dict.combodo-saml.php b/fr.dict.combodo-saml.php index e40278b..3cd4f83 100644 --- a/fr.dict.combodo-saml.php +++ b/fr.dict.combodo-saml.php @@ -11,7 +11,7 @@ */ Dict::Add('FR FR', 'French', 'Français', [ 'Menu:SAMLConfiguration' => 'Configuration SAML', - 'SAML:Error:CheckTheLogFileForMoreInformation' => 'Voir le fichier "log/saml.log" pour plus information', + 'SAML:Error:CheckTheLogFileForMoreInformation' => 'Voir le fichier journal pour plus information', 'SAML:Error:ErrorOccurred' => 'Une erreur est survenue', 'SAML:Error:Invalid_Attribute' => 'L\'authentification SAML a échoué car l\'attribut attendu \'%1$s\' n\'est pas présent dans le réponse de l\'Identity Provider (IdP). Consultez le fichier error.log pour plus d\'informations.', 'SAML:Error:NotAuthenticated' => 'Non authentifié', diff --git a/src/Logger.php b/src/Logger.php index c886f18..1d05a71 100644 --- a/src/Logger.php +++ b/src/Logger.php @@ -12,65 +12,28 @@ /** * Simple logger to write to log/saml.log */ -class Logger +class Logger extends IssueLog { - const ERROR = 'Error'; - const WARNING = 'Warning'; - const INFO = 'Info'; - const DEBUG = 'Debug'; + public const CHANNEL_DEFAULT = 'SAML'; + public const LEVEL_DEFAULT = self::LEVEL_ERROR; private static $bDebug = null; - private static function Log($sLogLevel, $sMessage) - { - if (static::$bDebug === null) - { - static::$bDebug = MetaModel::GetModuleSetting('combodo-saml', 'debug', false); - } - - if ((!static::$bDebug) && ($sLogLevel != static::ERROR)) - { - // If not in debug mode, log only ERROR messages - return; - } - - $sLogFile = APPROOT.'/log/saml.log'; - - $hLogFile = fopen($sLogFile, 'a'); - if ($hLogFile !== false) - { - flock($hLogFile, LOCK_EX); - $sDate = date('Y-m-d H:i:s'); - fwrite($hLogFile, "$sDate | $sLogLevel | $sMessage\n"); - fflush($hLogFile); - flock($hLogFile, LOCK_UN); - fclose($hLogFile); - } - else - { - IssueLog::Error("Cannot open log file '$sLogFile' for writing."); - IssueLog::Info($sMessage); - } - } - - public static function Error($sMessage) - { - static::Log(static::ERROR, $sMessage); - } - - - public static function Warning($sMessage) - { - static::Log(static::WARNING, $sMessage); - } - - public static function Info($sMessage) - { - static::Log(static::INFO, $sMessage); - } - - public static function Debug($sMessage) - { - static::Log(static::DEBUG, $sMessage); - } -} \ No newline at end of file + public static function GetMinLogLevel($sChannel, $sConfigKey = self::ENUM_CONFIG_PARAM_FILE) + { + if ($sChannel === static::CHANNEL_DEFAULT) + { + if (static::$bDebug === null) + { + static::$bDebug = MetaModel::GetModuleSetting('combodo-saml', 'debug', false); + } + + if (static::$bDebug) + { + return static::LEVEL_TRACE; + } + } + + return parent::GetMinLogLevel($sChannel, $sConfigKey); + } +}