mirror of
https://gitlab.easter-eggs.com/ee/ldapsaisie.git
synced 2024-11-22 09:59:06 +01:00
Improve logging
This commit is contained in:
parent
3acebcfe94
commit
f64cc3cc19
15 changed files with 940 additions and 81 deletions
165
doc/conf/LSlog.docbook
Normal file
165
doc/conf/LSlog.docbook
Normal file
|
@ -0,0 +1,165 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<sect3 id="config-LSlog">
|
||||
<title>Configuration de la journalisation</title>
|
||||
|
||||
<para>Cette section décrit le tableau de configuration de la journalisation
|
||||
de l'application.</para>
|
||||
|
||||
<programlisting linenumbering="unnumbered">
|
||||
<citetitle>Structure</citetitle>...
|
||||
<![CDATA[$GLOBALS['LSlog'] = array(
|
||||
'enable' => [booléen],
|
||||
'level' => '[niveau]',
|
||||
'handlers' => array(
|
||||
'[handler 1]',
|
||||
array (
|
||||
'handler' => [handler 2],
|
||||
'level' => '[niveau]',
|
||||
// Autres paramètres propre à cet handler
|
||||
[...]
|
||||
),
|
||||
[...]
|
||||
),
|
||||
);]]>
|
||||
...
|
||||
</programlisting>
|
||||
|
||||
<!-- Début Paramètres Configuration -->
|
||||
<variablelist>
|
||||
<title>Paramètres de configuration</title>
|
||||
|
||||
<varlistentry>
|
||||
<term>enable</term>
|
||||
<listitem>
|
||||
<simpara>Booléen permatant d'activer ou désactiver complètement la
|
||||
journalisation. Par défaut : <literal>False</literal></simpara>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term>level</term>
|
||||
<listitem>
|
||||
<simpara>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) :
|
||||
<itemizedlist>
|
||||
<listitem>DEBUG</listitem>
|
||||
<listitem>INFO</listitem>
|
||||
<listitem>WARNING</listitem>
|
||||
<listitem>ERROR</listitem>
|
||||
<listitem>FATAL</listitem>
|
||||
</itemizedlist>
|
||||
</simpara>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term>handlers</term>
|
||||
<listitem>
|
||||
<para>Tableau permettant de configurer les <emphasis>handlers</emphasis> de la
|
||||
journalisation. Chaque <emphasis>handler</emphasis> gère les messages
|
||||
journalisés d'une manière qui lui est propre.</para>
|
||||
|
||||
<para>Plusieurs <emphasis>handlers</emphasis> peuvent être configurés en même
|
||||
temps (y compris plusieurs <emphasis>handlers</emphasis> du même type).</para>
|
||||
|
||||
<para>Ce tableau peut contenir simplement le nom du type de <emphasis>handler
|
||||
</emphasis>à utiliser ou bien des tableaux configurant un à un chacun des
|
||||
<emphasis>handlers</emphasis>. Dans ce second cas, la structure de la
|
||||
configuration d'un <emphasis>handler</emphasis> est la suivante :</para>
|
||||
|
||||
<programlisting linenumbering="unnumbered">
|
||||
<citetitle>Structure</citetitle>...
|
||||
<![CDATA[array(
|
||||
'handler' => [type],
|
||||
'level' => '[niveau]',
|
||||
// Autres paramètres propre à ce handler
|
||||
[...]
|
||||
)]]>
|
||||
...
|
||||
</programlisting>
|
||||
|
||||
<variablelist>
|
||||
<title>Paramètres de configuration d'un handler</title>
|
||||
|
||||
<varlistentry>
|
||||
<term>handler</term>
|
||||
<listitem>
|
||||
<simpara>Type du <emphasis>handler</emphasis> (voir ci-dessous).</simpara>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term>level</term>
|
||||
<listitem>
|
||||
<simpara>Ce paramètre défini le niveau minimum de la journalisation
|
||||
spécifique à cet <emphasis>handler</emphasis>. 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 <literal>$GLOBALS['LSlog']['level']
|
||||
</literal>.</simpara>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
</variablelist>
|
||||
|
||||
<para>Il existe plusieurs types d'<emphasis>handlers</emphasis> gérés par
|
||||
l'application :</para>
|
||||
<variablelist>
|
||||
<varlistentry>
|
||||
<term>file</term>
|
||||
<listitem>
|
||||
<simpara>Journalisation dans un simple fichier texte. Le chemin du
|
||||
fichier peut être configuré via le paramètre <literal>path</literal>.
|
||||
Si ce paramètre est omis, le chemin du fichier par défaut est soit la
|
||||
valeur de la variable <literal>$GLOBALS['LSlog']['filename']</literal>
|
||||
(pour la rétro-compatibilité avec les anciennes versions d'LdapSaisie)
|
||||
ou à défaut : <literal>tmp/LS.log</literal>.</simpara>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term>syslog</term>
|
||||
<listitem>
|
||||
<simpara>Journalisation via le service <emphasis>syslog</emphasis>.
|
||||
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 : <literal>EMERG, ALERT, CRITICAL,
|
||||
ERROR, WARNING, NOTICE, INFO, DEBUG</literal></simpara>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term>system</term>
|
||||
<listitem>
|
||||
<simpara>Journalisation via le gestionnaire d'erreurs PHP. Cet <emphasis>
|
||||
handler</emphasis> utilise la fonction PHP <literal>error_log</literal>.
|
||||
Pour plus d'informations sur comment configurer le gestionnaire d'erreurs
|
||||
PHP, consulter la <ulink url='https://www.php.net/error_log'>documentation
|
||||
officielle</ulink>.</simpara>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term>email</term>
|
||||
<listitem>
|
||||
<simpara>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 <literal>recipient
|
||||
</literal>.</simpara>
|
||||
<note><para>Il est conseillé d'utiliser ce type d'<emphasis>handler</emphasis>
|
||||
avec un niveau minimum de journalisation important (<literal>FATAL</literal>
|
||||
recommandé) pour ne pas déclencher un nombre trop important d'envois d'emails.
|
||||
</para></note>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
</variablelist>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
</variablelist>
|
||||
<!-- Fim Paramètres Configuration -->
|
||||
|
||||
</sect3>
|
|
@ -5,6 +5,7 @@
|
|||
<!ENTITY conf-LSprofile SYSTEM "LSprofile.docbook">
|
||||
<!ENTITY conf-subDn SYSTEM "subDn.docbook">
|
||||
<!ENTITY conf-recoverPassword SYSTEM "recoverPassword.docbook">
|
||||
<!ENTITY conf-LSlog SYSTEM "LSlog.docbook">
|
||||
<!ENTITY conf-LSformat SYSTEM "LSformat.docbook">
|
||||
<!ENTITY conf-LDAP_search_params SYSTEM "LDAP_search_params.docbook">
|
||||
|
||||
|
|
|
@ -195,22 +195,15 @@ define('CONST2','val2')
|
|||
<varlistentry>
|
||||
<term>LSdebug</term>
|
||||
<listitem>
|
||||
<simpara>Variable booléenne déterminant si le mode debug est activé.</simpara>
|
||||
<simpara>Variable booléenne déterminant si le débogage à l'écran est activé.</simpara>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term>$GLOBALS['LSlog']['enable']</term>
|
||||
<term>$GLOBALS['LSlog']</term>
|
||||
<listitem>
|
||||
<simpara>Variable booléenne déterminant si les logs sont activés.</simpara>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term>$GLOBALS['LSlog']['filename']</term>
|
||||
<listitem>
|
||||
<simpara>Variable déterminant le chemin du fichier de log.</simpara>
|
||||
<simpara>Valeur par défaut : <emphasis>/tmp/LS.log</emphasis></simpara>
|
||||
<simpara>Variable permettant de configurer la journalisation de l'application.
|
||||
<link linkend="config-LSlog">Voir section concernée</link>.</simpara>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
|
@ -255,6 +248,8 @@ define('CONST2','val2')
|
|||
|
||||
</variablelist>
|
||||
|
||||
&conf-LSlog;
|
||||
|
||||
</sect2>
|
||||
|
||||
&conf-LSformat;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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}"));
|
||||
|
||||
|
|
369
public_html/includes/class/class.LSlog.php
Normal file
369
public_html/includes/class/class.LSlog.php
Normal file
|
@ -0,0 +1,369 @@
|
|||
<?php
|
||||
/*******************************************************************************
|
||||
* Copyright (C) 2007 Easter-eggs
|
||||
* http://ldapsaisie.labs.libre-entreprise.org
|
||||
*
|
||||
* Author: See AUTHORS file in top-level directory.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License version 2
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
* Handle logging
|
||||
*
|
||||
* @author Benjamin Renard <brenard@easter-eggs.com>
|
||||
*/
|
||||
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}.")
|
||||
);
|
||||
|
58
public_html/includes/class/class.LSlog_email.php
Normal file
58
public_html/includes/class/class.LSlog_email.php
Normal file
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
/*******************************************************************************
|
||||
* Copyright (C) 2007 Easter-eggs
|
||||
* http://ldapsaisie.labs.libre-entreprise.org
|
||||
*
|
||||
* Author: See AUTHORS file in top-level directory.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License version 2
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
* Handle logging to email (using error_log PHP function with message_type = 1)
|
||||
*
|
||||
* @author Benjamin Renard <brenard@easter-eggs.com>
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
57
public_html/includes/class/class.LSlog_file.php
Normal file
57
public_html/includes/class/class.LSlog_file.php
Normal file
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
/*******************************************************************************
|
||||
* Copyright (C) 2007 Easter-eggs
|
||||
* http://ldapsaisie.labs.libre-entreprise.org
|
||||
*
|
||||
* Author: See AUTHORS file in top-level directory.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License version 2
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
* Handle logging to file (using error_log PHP function with message_type = 3)
|
||||
*
|
||||
* @author Benjamin Renard <brenard@easter-eggs.com>
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
96
public_html/includes/class/class.LSlog_handler.php
Normal file
96
public_html/includes/class/class.LSlog_handler.php
Normal file
|
@ -0,0 +1,96 @@
|
|||
<?php
|
||||
/*******************************************************************************
|
||||
* Copyright (C) 2007 Easter-eggs
|
||||
* http://ldapsaisie.labs.libre-entreprise.org
|
||||
*
|
||||
* Author: See AUTHORS file in top-level directory.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License version 2
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
* Default logging handler
|
||||
*
|
||||
* @author Benjamin Renard <brenard@easter-eggs.com>
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
98
public_html/includes/class/class.LSlog_syslog.php
Normal file
98
public_html/includes/class/class.LSlog_syslog.php
Normal file
|
@ -0,0 +1,98 @@
|
|||
<?php
|
||||
/*******************************************************************************
|
||||
* Copyright (C) 2007 Easter-eggs
|
||||
* http://ldapsaisie.labs.libre-entreprise.org
|
||||
*
|
||||
* Author: See AUTHORS file in top-level directory.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License version 2
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
* Handle logging to syslog
|
||||
*
|
||||
* @author Benjamin Renard <brenard@easter-eggs.com>
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
41
public_html/includes/class/class.LSlog_system.php
Normal file
41
public_html/includes/class/class.LSlog_system.php
Normal file
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
/*******************************************************************************
|
||||
* Copyright (C) 2007 Easter-eggs
|
||||
* http://ldapsaisie.labs.libre-entreprise.org
|
||||
*
|
||||
* Author: See AUTHORS file in top-level directory.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License version 2
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
* Handle system logging (using error_log PHP function)
|
||||
*
|
||||
* @author Benjamin Renard <brenard@easter-eggs.com>
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
|
@ -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 !");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -125,6 +125,22 @@ class LSsession {
|
|||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lancement de LSlog
|
||||
*
|
||||
* @author Benjamin Renard <brenard@easter-eggs.com>
|
||||
*
|
||||
* @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();
|
||||
|
|
|
@ -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])) {
|
||||
|
|
Loading…
Reference in a new issue