Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion en.dict.combodo-saml.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion en_gb.dict.combodo-saml.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion fr.dict.combodo-saml.php
Original file line number Diff line number Diff line change
Expand Up @@ -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é',
Expand Down
79 changes: 21 additions & 58 deletions src/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
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);
}
}