diff --git a/doc/conf/LSlog.docbook b/doc/conf/LSlog.docbook new file mode 100644 index 00000000..723bd3d0 --- /dev/null +++ b/doc/conf/LSlog.docbook @@ -0,0 +1,165 @@ + + + Configuration de la journalisation + +Cette section décrit le tableau de configuration de la journalisation +de l'application. + + +Structure... + [booléen], + 'level' => '[niveau]', + 'handlers' => array( + '[handler 1]', + array ( + 'handler' => [handler 2], + 'level' => '[niveau]', + // Autres paramètres propre à cet handler + [...] + ), + [...] + ), +);]]> +... + + + + +Paramètres de configuration + + + enable + + Booléen permatant d'activer ou désactiver complètement la + journalisation. Par défaut : False + + + + + level + + Ce paramètre défini le niveau minimum de la journalisation : + tous les messages des niveaux inférieurs ne seront pas inclus dans le + journal de l'application. Les niveaux de journalisation gérés par + l'application sont (dans l'ordre du plus petit au plus grand) : + + DEBUG + INFO + WARNING + ERROR + FATAL + + + + + + + handlers + + Tableau permettant de configurer les handlers de la + journalisation. Chaque handler gère les messages + journalisés d'une manière qui lui est propre. + + Plusieurs handlers peuvent être configurés en même + temps (y compris plusieurs handlers du même type). + + Ce tableau peut contenir simplement le nom du type de handler + à utiliser ou bien des tableaux configurant un à un chacun des + handlers. Dans ce second cas, la structure de la + configuration d'un handler est la suivante : + + +Structure... + [type], + 'level' => '[niveau]', + // Autres paramètres propre à ce handler + [...] +)]]> +... + + + + Paramètres de configuration d'un handler + + + handler + + Type du handler (voir ci-dessous). + + + + + level + + Ce paramètre défini le niveau minimum de la journalisation + spécifique à cet handler. Si ce paramètre est omis, + le niveau global sera utilisé. Les valeurs possibles de ce paramètre + sont les mêmes que pour le paramètre $GLOBALS['LSlog']['level'] + . + + + + + + Il existe plusieurs types d'handlers gérés par + l'application : + + + file + + Journalisation dans un simple fichier texte. Le chemin du + fichier peut être configuré via le paramètre path. + Si ce paramètre est omis, le chemin du fichier par défaut est soit la + valeur de la variable $GLOBALS['LSlog']['filename'] + (pour la rétro-compatibilité avec les anciennes versions d'LdapSaisie) + ou à défaut : tmp/LS.log. + + + + + syslog + + Journalisation via le service syslog. + Il est possible de configurer une priorité systématique pour les + messages journalisés. À défaut, la priorité sera déterminée + automatiquement en fonction du niveau du message. Les valeurs + possibles de ce paramètre sont : EMERG, ALERT, CRITICAL, + ERROR, WARNING, NOTICE, INFO, DEBUG + + + + + system + + Journalisation via le gestionnaire d'erreurs PHP. Cet + handler utilise la fonction PHP error_log. + Pour plus d'informations sur comment configurer le gestionnaire d'erreurs + PHP, consulter la documentation + officielle. + + + + + email + + Journalisation via l'envoi d'un email : chaque message journalisé + déclenchera l'envoi d'un email au destinataire configuré. L'adresse email + du destinataire peut-être configurée via le paramètre recipient + . + Il est conseillé d'utiliser ce type d'handler + avec un niveau minimum de journalisation important (FATAL + recommandé) pour ne pas déclencher un nombre trop important d'envois d'emails. + + + + + + + + + + + + diff --git a/doc/conf/conf.entities.xml b/doc/conf/conf.entities.xml index f6cec44d..079a8a7b 100644 --- a/doc/conf/conf.entities.xml +++ b/doc/conf/conf.entities.xml @@ -5,6 +5,7 @@ + diff --git a/doc/conf/globale.docbook b/doc/conf/globale.docbook index 71aba2fc..0b7d875d 100644 --- a/doc/conf/globale.docbook +++ b/doc/conf/globale.docbook @@ -195,22 +195,15 @@ define('CONST2','val2') LSdebug - Variable booléenne déterminant si le mode debug est activé. + Variable booléenne déterminant si le débogage à l'écran est activé. - $GLOBALS['LSlog']['enable'] + $GLOBALS['LSlog'] - Variable booléenne déterminant si les logs sont activés. - - - - - $GLOBALS['LSlog']['filename'] - - Variable déterminant le chemin du fichier de log. - Valeur par défaut : /tmp/LS.log + Variable permettant de configurer la journalisation de l'application. + Voir section concernée. @@ -255,6 +248,8 @@ define('CONST2','val2') +&conf-LSlog; + &conf-LSformat; diff --git a/public_html/conf/config.inc.php b/public_html/conf/config.inc.php index ea956777..ea417ffa 100644 --- a/public_html/conf/config.inc.php +++ b/public_html/conf/config.inc.php @@ -184,8 +184,31 @@ define('LS_CSS_DIR', 'css'); //Debug define('LSdebug',false); -// Logs -$GLOBALS['LSlog']['filename'] = 'tmp/LS.log'; +// Logging +$GLOBALS['LSlog']['handlers'] = array ( + array ( + 'handler' => 'file', + 'path' => 'tmp/LS.log', + ), + array ( + 'handler' => 'email', // Email handler (each logged message generated an email) + 'level' => 'FATAL', + 'recipient' => 'root@localhost', // Email recipient + ), + /* + array ( + 'handler' => 'syslog', // Syslog handler + //'priority' => 'WARNING', // Force priority : EMERG, ALERT, CRITICAL, ERROR, WARNING, NOTICE, INFO, DEBUG + ), + */ + /* + array ( + 'handler' => 'system', // System logging (using PHP error_log) + 'level' => 'ERROR', + ), + */ +); +$GLOBALS['LSlog']['level'] = 'DEBUG'; // DEBUG, INFO, WARNING, ERROR, FATAL $GLOBALS['LSlog']['enable'] = true; define('NB_LSOBJECT_LIST',30); diff --git a/public_html/includes/class/class.LSauthMethod_anonymous.php b/public_html/includes/class/class.LSauthMethod_anonymous.php index 45b31925..dc682647 100644 --- a/public_html/includes/class/class.LSauthMethod_anonymous.php +++ b/public_html/includes/class/class.LSauthMethod_anonymous.php @@ -35,7 +35,7 @@ class LSauthMethod_anonymous extends LSauthMethod { return; if ( (!defined('LSAUTHMETHOD_ANONYMOUS_DISABLE_LOGOUT')) || (constant('LSAUTHMETHOD_ANONYMOUS_DISABLE_LOGOUT') === True)) { - LSlog('logout : '.constant('LSAUTHMETHOD_ANONYMOUS_DISABLE_LOGOUT')); + LSlog :: debug('logout : '.constant('LSAUTHMETHOD_ANONYMOUS_DISABLE_LOGOUT')); LSauth :: disableLogoutBtn(); } diff --git a/public_html/includes/class/class.LSerror.php b/public_html/includes/class/class.LSerror.php index 57dd4939..93083e77 100644 --- a/public_html/includes/class/class.LSerror.php +++ b/public_html/includes/class/class.LSerror.php @@ -64,7 +64,8 @@ class LSerror { */ public static function addErrorCode($code=-1,$msg='') { $_SESSION['LSerror'][] = array($code,$msg); - LSlog('[ERROR] '.self::getError(array($code,$msg))); + if (class_exists('LSlog')) + LSlog :: error(self::getError(array($code,$msg))); } /** @@ -172,56 +173,10 @@ class LSerror { return; } - /** - * PHP error handler (see set_error_handler() function doc) - **/ - public static function errorHandler($errno, $errstr, $errfile, $errline) { - self :: addErrorCode(-2,"Error ".self :: convertPHPErrorNo($errno)." occured in file $errfile (line : $errline) : $errstr"); - if ( E_RECOVERABLE_ERROR===$errno ) { - throw new ErrorException($errstr, $errno, 0, $errfile, $errline); - } - return False; - } - - /** - * Convert PHP error number to string - * - * @param[in] $errno int Error number - * - * @retval string Corresponding error name - **/ - public static function convertPHPErrorNo($errno) { - $error_levels=array ( - 1 => "ERROR", - 2 => "WARNING", - 4 => "PARSE", - 8 => "NOTICE", - 16 => "CORE_ERROR", - 32 => "CORE_WARNING", - 64 => "COMPILE_ERROR", - 128 => "COMPILE_WARNING", - 256 => "USER_ERROR", - 512 => "USER_WARNING", - 1024 => "USER_NOTICE", - 2048 => "STRICT", - 4096 => "RECOVERABLE_ERROR", - 8192 => "DEPRECATED", - 16384 => "USER_DEPRECATED", - 32767 => "ALL", - ); - if (isset($error_levels[$errno])) { - return $error_levels[$errno]; - } - else { - return "UNKNOWN_ERROR"; - } - } - } /* * Error Codes */ LSerror :: defineError(-1,_("Unknown error : %{error}")); -LSerror :: defineError(-2,_("PHP error : %{error}")); diff --git a/public_html/includes/class/class.LSlog.php b/public_html/includes/class/class.LSlog.php new file mode 100644 index 00000000..21ebb3ec --- /dev/null +++ b/public_html/includes/class/class.LSlog.php @@ -0,0 +1,369 @@ + + */ +class LSlog { + + // Enable state + private static $enabled = false; + + // Configured handlers + private static $handlers = array(); + + // Default handlers (if not configured) + private static $default_handlers = array( + array ( + 'handler' => 'file', + ), + ); + + // Current level + private static $level; + private static $default_level = 'WARNING'; + + // Levels + private static $levels=array( + 'DEBUG' => 0, + 'INFO' => 1, + 'WARNING' => 2, + 'ERROR' => 3, + 'FATAL' => 4, + ); + + /** + * Start/initialize logging + * + * @retval bool True on success, False otherwise + **/ + public static function start() { + // Load configuration + self :: $enabled = self :: getConfig('enable', false, 'bool'); + self :: $level = self :: getConfig('level', self :: $default_level, 'string'); + if (!array_key_exists(self :: $level, self :: $levels)) self :: $level = 'WARNING'; + + // Load default handlers class + if (!LSsession :: loadLSclass('LSlog_handler', null, true)) { + LSdebug('LSlog disabled'); + return False; + } + + // Load handlers + $handlers = self :: getConfig('handlers'); + if (!is_array($handlers)) $handlers = self :: $default_handlers; + LSdebug($handlers, true); + $debug_handlers = array(); + foreach($handlers as $handler => $handler_config) { + if (!is_array($handler_config)) + $handler_config = array('handler' => $handler); + else + $handler = (isset($handler_config['handler'])?$handler_config['handler']:'system'); + + $handler_class = "LSlog_$handler"; + + // Load handler class + if (!LSsession :: loadLSclass($handler_class) || !class_exists($handler_class)) { + LSerror :: addErrorCode('LSlog_01', $handler); + continue; + } + + $handler_obj = new $handler_class($handler_config); + if ($handler_obj -> checkCompatibility()) + self :: $handlers[] = $handler_obj; + else + LSdebug("LSlog handler $handler not supported."); + $debug_handlers[] = $handler; + } + LSdebug('LSlog enabled with level='.self :: $level.' and following handlers : '.implode(', ', $debug_handlers)); + + // Set PHP error/exception handlers + if (self :: $level == 'DEBUG') + set_error_handler(array('LSlog', 'php_error'), E_ALL & ~E_STRICT); + else + set_error_handler(array('LSlog', 'php_error'), E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED); + set_exception_handler(array('LSlog', 'exception')); + + return True; + } + + /** + * Get a configuration variable value + * + * @param[in] $var string The configuration variable name + * @param[in] $default mixed The default value to return if configuration variable + * is not set (Default : null) + * @param[in] $cast string The type of expected value. The configuration variable + * value will be cast as this type. Could be : bool, int, + * float or string. (Optional, default : raw value) + * + * @retval mixed The configuration variable value + **/ + public static function getConfig($var, $default=null, $cast=null) { + return LSconfig :: get($var, $default, $cast, ((isset($GLOBALS['LSlog']) && is_array($GLOBALS['LSlog']))?$GLOBALS['LSlog']:array())); + } + + /** + * Log a message + * + * @param[in] $level string The message level + * @param[in] $message string The message + * + * @retval void + **/ + private static function logging($level, $message) { + // Check LSlog is enabled + if (!self :: $enabled) + return; + + // Check/fix level + if (!array_key_exists($level, self :: $levels)) + $level = self :: $default_level; + + + // Add prefix + if (php_sapi_name() == "cli") { + global $argv; + $message = basename($argv[0])." - $level - $message"; + } + else { + $message = $_SERVER['REQUEST_URI'].' - '.$_SERVER['REMOTE_ADDR'].' - '.self :: getLdapServerName().' - '.self :: getAuthenticatedUserDN()." - $level - $message"; + } + + foreach (self :: $handlers as $handler) { + // Check handler level + if (!$handler -> checkLevel($level)) + continue; + + // Logging on this handler + call_user_func(array($handler, 'logging'), $level, $message); + } + } + + /** + * Check level against configured level + * + * @param[in] $level string The level + * @param[in] $configured_level string|null The configured level (optional, default : self :: $level) + * + * @retval bool True if a message with this level have to be logged, False otherwise + **/ + public static function checkLevel($level, $configured_level=null) { + if (is_null($configured_level) || !array_key_exists($configured_level, self :: $levels)) + $configured_level = self :: $level; + + // On unknown level, use default level + if (!array_key_exists($level, self :: $levels)) + $level = self :: $default_level; + + return (self :: $levels[$level] >= self :: $levels[$configured_level]); + } + + /** + * Helper to retreive current LDAP server name + * + * @retval string Current LDAP server name + **/ + private static function getLdapServerName() { + if (LSsession :: $ldapServer) { + if (isset(LSsession :: $ldapServer['name'])) + return LSsession :: $ldapServer['name']; + else + return "#".LSsession :: $ldapServerId; + } + return "Not connected"; + } + + /** + * Helper to retreive current authenticated user DN + * + * @retval string Current authenticated user DN + **/ + private static function getAuthenticatedUserDN() { + $auth_dn = LSsession :: getLSuserObjectDn(); + if ($auth_dn) + return LSsession :: getLSuserObjectDn(); + return "Anonymous"; + } + + /* + * PHP error logging helpers + */ + + /** + * Generate current context backtrace + * + * @retval string Current context backtrace + **/ + public static function get_debug_backtrace_context() { + $traces = debug_backtrace(); + if (!is_array($traces) || count($traces) <= 2) + return ""; + + $msg = array(); + for ($i=2; $i < count($traces); $i++) { + $trace = array("#$i"); + if (isset($traces[$i]['file'])) + $trace[] = $traces[$i]['file'].(isset($traces[$i]['line'])?":".$traces[$i]['line']:""); + if (isset($traces[$i]['class']) && isset($traces[$i]['function'])) + $trace[] = $traces[$i]['class'] . " " . $traces[$i]['type'] . " " . $traces[$i]['function']. "()"; + elseif (isset($traces[$i]['function'])) + $trace[] = $traces[$i]['function']. "()"; + $msg[] = implode(" - ", $trace); + } + + return implode("\n", $msg); + } + + /** + * PHP set_exception_handler helper + * + * @see https://www.php.net/set_exception_handler + **/ + public static function exception($exception, $prefix=null, $fatal=true) { + $message = ($prefix?"$prefix :\n":"An exception occured :\n"). self :: get_debug_backtrace_context(). "\n" . + "## ".$exception->getFile().":".$exception->getLine(). " : ". $exception->getMessage(); + if ($fatal) + self :: fatal($message); + else + self :: error($message); + } + + /** + * PHP set_error_handler helper + * + * @see https://www.php.net/set_error_handler + **/ + public static function php_error($errno, $errstr, $errfile, $errline) { + $errnos2error = array ( + 1 => "ERROR", + 2 => "WARNING", + 4 => "PARSE", + 8 => "NOTICE", + 16 => "CORE_ERROR", + 32 => "CORE_WARNING", + 64 => "COMPILE_ERROR", + 128 => "COMPILE_WARNING", + 256 => "USER_ERROR", + 512 => "USER_WARNING", + 1024 => "USER_NOTICE", + 2048 => "STRICT", + 4096 => "RECOVERABLE_ERROR", + 8192 => "DEPRECATED", + 16384 => "USER_DEPRECATED", + 32767 => "ALL", + ); + + $errors2level = array ( + "ERROR" => "ERROR", + "WARNING" => "WARNING", + "PARSE" => "FATAL", + "NOTICE" => "INFO", + "CORE_ERROR" => "ERROR", + "CORE_WARNING" => "WARNING", + "COMPILE_ERROR" => "ERROR", + "COMPILE_WARNING" => "WARNING", + "USER_ERROR" => "ERROR", + "USER_WARNING" => "WARNING", + "USER_NOTICE" => "INFO", + "STRICT" => "WARNING", + "RECOVERABLE_ERROR" => "WARNING", + "DEPRECATED" => "DEBUG", + "USER_DEPRECATED" => "DEBUG", + "ALL" => "ERROR", + "UNKNOWN" => "ERROR", + ); + $error = (isset($errnos2error[$errno])?$errnos2error[$errno]:'UNKNOWN'); + $level = (isset($errors2level[$error])?$errors2level[$error]:'ERROR'); + self :: logging($level, "A PHP $error occured (#$errno) : $errstr [$errfile:$errline]"); + return False; + } + + /* + * Public logging methods + */ + + /** + * Log a message with level DEBUG + * + * @param[in] $message The message to log + * + * @retval void + **/ + public static function debug($message) { + self :: logging('DEBUG', $message); + } + + /** + * Log a message with level INFO + * + * @param[in] $message The message to log + * + * @retval void + **/ + public static function info($message) { + self :: logging('INFO', $message); + } + + /** + * Log a message with level WARNING + * + * @param[in] $message The message to log + * + * @retval void + **/ + public static function warning($message) { + self :: logging('WARNING', $message); + } + + /** + * Log a message with level ERROR + * + * @param[in] $message The message to log + * + * @retval void + **/ + public static function error($message) { + self :: logging('ERROR', $message); + } + + /** + * Log a message with level FATAL + * + * @param[in] $message The message to log + * + * @retval void + **/ + public static function fatal($message) { + self :: logging('FATAL', $message); + } +} + +/** + * Error Codes + */ +LSerror :: defineError('LSlog_01', +_("LSlog : Fail to load logging handler %{handler}.") +); + diff --git a/public_html/includes/class/class.LSlog_email.php b/public_html/includes/class/class.LSlog_email.php new file mode 100644 index 00000000..6dd8aa34 --- /dev/null +++ b/public_html/includes/class/class.LSlog_email.php @@ -0,0 +1,58 @@ + + */ +class LSlog_email extends LSlog_handler { + + // The configured email recipient + private $recipient = null; + + /** + * Constructor + * + * @param[in] $config array The handler configuration + * + * @retval void + **/ + public function __construct($config) { + parent :: __construct($config); + $this -> recipient = self :: getConfig('recipient'); + } + + /** + * Log a message + * + * @param[in] $level string The message level + * @param[in] $message string The message + * + * @retval void + **/ + public function logging($level, $message) { + if ($this -> recipient) + return error_log($message, 1, $this -> recipient); + return false; + } +} diff --git a/public_html/includes/class/class.LSlog_file.php b/public_html/includes/class/class.LSlog_file.php new file mode 100644 index 00000000..233c9233 --- /dev/null +++ b/public_html/includes/class/class.LSlog_file.php @@ -0,0 +1,57 @@ + + */ +class LSlog_file extends LSlog_handler { + + // The configured logfile path + private $path; + + /** + * Constructor + * + * @param[in] $config array The handler configuration + * + * @retval void + **/ + public function __construct($config) { + parent :: __construct($config); + // For reto-compatibilty, use LSlog.filename as default log path value + $this -> path = self :: getConfig('path', LSlog :: getConfig('filename', 'tmp/LS.log')); + } + + /** + * Log a message + * + * @param[in] $level string The message level + * @param[in] $message string The message + * + * @retval void + **/ + public function logging($level, $message) { + return error_log(date('Y/m/d H:i:s').' - '.$message."\n", 3, $this -> path); + } +} diff --git a/public_html/includes/class/class.LSlog_handler.php b/public_html/includes/class/class.LSlog_handler.php new file mode 100644 index 00000000..0a6d625d --- /dev/null +++ b/public_html/includes/class/class.LSlog_handler.php @@ -0,0 +1,96 @@ + + */ +class LSlog_handler { + + // The handler configuration + private $config; + + /** + * Constructor + * + * @param[in] $config array The handler configuration + * + * @retval void + **/ + public function __construct($config) { + $this -> config = $config; + } + + /** + * Check system compatibility with this handler + * + * Note : LSlog do not generate no error about imcompatibly, it's + * just omit this handler if system is incompatible. You have to + * trigger it with this method if you want. + * + * @retval bool True if system is compatible, False otherwise + **/ + public function checkCompatibility() { + return True; + } + + /** + * Get a configuration variable value + * + * @param[in] $var string The configuration variable name + * @param[in] $default mixed The default value to return if configuration variable + * is not set (Default : null) + * @param[in] $cast string The type of expected value. The configuration variable + * value will be cast as this type. Could be : bool, int, + * float or string. (Optional, default : raw value) + * + * @retval mixed The configuration variable value + **/ + public function getConfig($var, $default=null, $cast=null) { + return LSconfig :: get($var, $default, $cast, $this -> config); + } + + /** + * Check level against configured level + * + * @param[in] $level string The level + * + * @retval bool True if a message with this level have to be logged, False otherwise + **/ + public function checkLevel($level) { + return LSlog :: checkLevel($level, $this -> getConfig('level')); + } + + /** + * Log a message + * + * @param[in] $level string The message level + * @param[in] $message string The message + * + * @retval void + **/ + public function logging($level, $message) { + return false; + } +} + diff --git a/public_html/includes/class/class.LSlog_syslog.php b/public_html/includes/class/class.LSlog_syslog.php new file mode 100644 index 00000000..39da2aba --- /dev/null +++ b/public_html/includes/class/class.LSlog_syslog.php @@ -0,0 +1,98 @@ + + */ +class LSlog_syslog extends LSlog_handler { + + // Force syslog priority + private $priority = null; + + // Levels to syslog priority mapping + private static $levels2priority = array ( + 'EMERG' => LOG_EMERG, // system is unusable + 'ALERT' => LOG_ALERT, // action must be taken immediately + 'CRITICAL' => LOG_CRIT, // critical conditions + 'ERROR' => LOG_ERR, // error conditions + 'WARNING' => LOG_WARNING, // warning conditions + 'NOTICE' => LOG_NOTICE, // normal, but significant, condition + 'INFO' => LOG_INFO, // informational message + 'DEBUG' => LOG_DEBUG, // debug-level message + ); + + // Default syslog priority (used if level is not provided or invalid) + private static $default_priority = LOG_WARNING; + + /** + * Constructor + * + * @param[in] $config array The handler configuration + * + * @retval void + **/ + public function __construct($config) { + parent :: __construct($config); + $this -> priority = static :: getConfig('priority'); + } + + /** + * Check system compatibility with this handler + * + * @retval bool True if system is compatible, False otherwise + **/ + public function checkCompatibility() { + return function_exists('syslog'); + } + + /** + * Log a message + * + * @param[in] $level string The message level + * @param[in] $message string The message + * + * @retval void + **/ + public function logging($level, $message) { + return syslog( + $this -> level2priority($level), + $message + ); + } + + /** + * Get syslog corresponding priority to a specific log level + * + * @param[in] $level string The log level + * + * @retval int Syslog corresponding priority + **/ + private function level2priority($level) { + if ($this -> priority && $level != $this -> priority) + return $this -> level2priority($this -> priority); + if (array_key_exists($level, static :: $levels2priority)) + return static :: $levels2priority[$level]; + return static :: $default_priority; + } +} diff --git a/public_html/includes/class/class.LSlog_system.php b/public_html/includes/class/class.LSlog_system.php new file mode 100644 index 00000000..38a1a8f2 --- /dev/null +++ b/public_html/includes/class/class.LSlog_system.php @@ -0,0 +1,41 @@ + + */ +class LSlog_system extends LSlog_handler { + + /** + * Log a message + * + * @param[in] $level string The message level + * @param[in] $message string The message + * + * @retval void + **/ + public function logging($level, $message) { + error_log($message); + } +} diff --git a/public_html/includes/class/class.LSsearchEntry.php b/public_html/includes/class/class.LSsearchEntry.php index 92801c8a..0b7a0df8 100644 --- a/public_html/includes/class/class.LSsearchEntry.php +++ b/public_html/includes/class/class.LSsearchEntry.php @@ -247,7 +247,7 @@ class LSsearchEntry { } } else { - LSlog('LSsearchEntry : '.$this -> dn.' => Unknown property '.$key.' !'); + LSlog :: warning('LSsearchEntry : '.$this -> dn.' => Unknown property '.$key.' !'); return __("Unknown property !"); } } diff --git a/public_html/includes/class/class.LSsession.php b/public_html/includes/class/class.LSsession.php index d6f73028..57ea1294 100644 --- a/public_html/includes/class/class.LSsession.php +++ b/public_html/includes/class/class.LSsession.php @@ -125,6 +125,22 @@ class LSsession { return; } + /** + * Lancement de LSlog + * + * @author Benjamin Renard + * + * @retval true si tout c'est bien passé, false sinon + */ + private static function startLSlog() { + if (self :: loadLSclass('LSlog')) { + if (LSlog :: start()) { + return true; + } + } + return False; + } + /** * Lancement et initialisation de Smarty * @@ -189,7 +205,6 @@ class LSsession { if(!self :: loadLSclass('LSerror')) { return; } - set_error_handler(array('LSerror','errorHandler'),E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED & ~E_WARNING); self :: defineLSerrors(); return true; } @@ -465,6 +480,7 @@ class LSsession { } self :: startLSerror(); + self :: startLSlog(); self :: startLStemplate(); session_start(); diff --git a/public_html/includes/functions.php b/public_html/includes/functions.php index c19e1c80..5f904b71 100644 --- a/public_html/includes/functions.php +++ b/public_html/includes/functions.php @@ -281,11 +281,12 @@ function LSdebug($data,$dump=false) { if ($dump) { $data=varDump($data); } - else if (!is_array($data) && !is_object($data)) { + LSlog :: debug($data); + + if (!is_array($data) && !is_object($data)) { $data="[$data]"; } $GLOBALS['LSdebug_fields'][]=$data; - LSlog('[DEBUG] '.$data); return true; } @@ -493,22 +494,6 @@ function LSdebugDefined() { return 1; } - function LSlog($msg,$dump=false) { - if ($GLOBALS['LSlog']['enable']) { - global $LSlogFile; - if (!$LSlogFile) { - $LSlogFile=fopen($GLOBALS['LSlog']['filename'],'a'); - } - if ($dump) { - $msg=varDump($msg); - } - else if (is_array($msg)||is_object($msg)) { - $msg = print_r($msg,true); - } - fwrite($LSlogFile,$_SERVER['REQUEST_URI']." : ".$msg."\n"); - } - } - function __($msg) { if (empty($msg)) return $msg; if (isset($GLOBALS['LSlang'][$msg])) {