Fix: Some fixes and enhancement into modularizing log functions

This commit is contained in:
Laurent Destailleur 2012-10-17 14:46:20 +02:00
parent b160b97cbe
commit 01bd20147e
8 changed files with 49 additions and 30 deletions

View File

@ -182,19 +182,25 @@ foreach ($syslogModules as $moduleName)
{
$module = new $moduleName;
$moduleactive=$module->isActive();
if ($moduleactive == -1 && empty($conf->global->MAIN_FEATURES_LEVEL)) continue; // Some modules are hidden if not activable and not into debug mode (end user must not see them)
$var=!$var;
print '<tr '.$bc[$var].'>';
print '<td width="140"><input '.$bc[$var].' type="checkbox" name="SYSLOG_HANDLERS[]" value="'.$moduleName.'" '.(in_array($moduleName, $activeModules) ? 'checked="checked"' : '').(!$module->isActive() ? 'disabled="disabled"' : '').'> ';
print $module->getName().'</td>';
print '<td width="140">';
print '<input '.$bc[$var].' type="checkbox" name="SYSLOG_HANDLERS[]" value="'.$moduleName.'" '.(in_array($moduleName, $activeModules) ? 'checked="checked"' : '').(!$moduleactive ? 'disabled="disabled"' : '').'> ';
print $module->getName();
print '</td>';
print '<td nowrap="nowrap">';
if ($module->configure())
$setuparray=$module->configure();
if ($setuparray)
{
foreach ($module->configure() as $option)
foreach ($setuparray as $option)
{
if (defined($option['constant'])) $value = constant($option['constant']);
else $value = (isset($option['default']) ? $option['default'] : '');
print $option['name'].': <input type="text" class="flat" name="'.$option['constant'].'" value="'.$value.'"'.(isset($option['attr']) ? ' '.$option['attr'] : '').'>';
}
}

View File

@ -2,6 +2,9 @@
require_once DOL_DOCUMENT_ROOT.'/core/modules/syslog/logHandlerInterface.php';
/**
* Parent class for log handlers
*/
class LogHandler
{
const STABLE = 'stable';
@ -10,6 +13,7 @@ class LogHandler
/**
* Content of the info tooltip.
*
* @return false|string
*/
public function getInfo()
@ -19,6 +23,7 @@ class LogHandler
/**
* Version of the module
*
* @return string
*/
public function getVersion()
@ -28,6 +33,7 @@ class LogHandler
/**
* ¿Is the module active?
*
* @return boolean
*/
public function isActive()
@ -37,6 +43,7 @@ class LogHandler
/**
* Configuration variables of the module
*
* @return array
*/
public function configure()
@ -48,6 +55,7 @@ class LogHandler
* Function that checks if the configuration is valid.
* It will be called after setting the configuration.
* The function returns an array with error messages
*
* @return array
*/
public function checkConfiguration()

View File

@ -27,7 +27,7 @@ class mod_syslog_chromephp extends LogHandler implements LogHandlerInterface
{
global $langs;
return $langs->trans('ChromePHPIncludePathWarning');
return $this->isActive()?'':$langs->trans('ClassNotFoundIntoPathWarning','ChromePhp.class.php');
}
/**
@ -35,22 +35,24 @@ class mod_syslog_chromephp extends LogHandler implements LogHandlerInterface
*/
public function isActive()
{
global $conf;
try
{
set_include_path(SYSLOG_CHROMEPHP_INCLUDEPATH);
if (empty($conf->global->SYSLOG_CHROMEPHP_INCLUDEPATH)) $conf->global->SYSLOG_CHROMEPHP_INCLUDEPATH='/usr/share/php';
set_include_path($conf->global->SYSLOG_CHROMEPHP_INCLUDEPATH);
$res = @include_once 'ChromePhp.class.php';
restore_include_path();
if ($res)
{
return true;
return 1;
}
}
catch(Exception $e)
{
print '<!-- FirePHP no available into PHP -->'."\n";
print '<!-- ChromePHP not available into PHP -->'."\n";
}
return false;
return -1;
}
/**
@ -59,7 +61,7 @@ class mod_syslog_chromephp extends LogHandler implements LogHandlerInterface
public function configure()
{
global $langs;
return array(
array(
'name' => $langs->trans('IncludePath'),
@ -82,11 +84,11 @@ class mod_syslog_chromephp extends LogHandler implements LogHandlerInterface
$oldinclude = get_include_path();
set_include_path(SYSLOG_CHROMEPHP_INCLUDEPATH);
if (!file_exists('ChromePhp.php'))
if (!file_exists('ChromePhp.class.php'))
{
$errors[] = $langs->trans("ErrorFailedToOpenFile", 'ChromePhp.php');
$errors[] = $langs->trans("ErrorFailedToOpenFile", 'ChromePhp.class.php');
}
set_include_path($oldinclude);
return $errors;
@ -106,7 +108,7 @@ class mod_syslog_chromephp extends LogHandler implements LogHandlerInterface
// database or config file because we must be able to log data before database or config file read.
$oldinclude=get_include_path();
set_include_path(SYSLOG_CHROMEPHP_INCLUDEPATH);
include_once 'ChromePhp.php';
include_once 'ChromePhp.class.php';
set_include_path($oldinclude);
ob_start(); // To be sure headers are not flushed until all page is completely processed
if ($level == LOG_ERR) ChromePhp::error($message);

View File

@ -37,7 +37,7 @@ class mod_syslog_file extends LogHandler implements LogHandlerInterface
*/
public function isActive()
{
return true;
return 1;
}
/**
@ -46,7 +46,7 @@ class mod_syslog_file extends LogHandler implements LogHandlerInterface
public function configure()
{
global $langs;
return array(
array(
'name' => $langs->trans('SyslogFilename'),
@ -67,7 +67,7 @@ class mod_syslog_file extends LogHandler implements LogHandlerInterface
$errors = array();
$filename = $this->getFilename();
if (file_exists($filename) && is_writable($filename))
{
dol_syslog('admin/syslog: file '.$filename);
@ -112,7 +112,7 @@ class mod_syslog_file extends LogHandler implements LogHandlerInterface
LOG_INFO => 'INFO',
LOG_DEBUG => 'DEBUG'
);
$message = dol_print_date(time(),"%Y-%m-%d %H:%M:%S")." ".sprintf("%-5s", $logLevels[$content['level']])." ".sprintf("%-15s", $content['ip'])." ".$content['message'];
fwrite($filefd, $message."\n");

View File

@ -27,7 +27,7 @@ class mod_syslog_firephp extends LogHandler implements LogHandlerInterface
{
global $langs;
return $langs->trans('FirePHPIncludePathWarning');
return $langs->trans('ClassNotFoundIntoPathWarning','FirePHPCore/FirePHP.class.php');
}
/**
@ -42,7 +42,7 @@ class mod_syslog_firephp extends LogHandler implements LogHandlerInterface
restore_include_path();
if ($res)
{
return true;
return 1;
}
}
catch(Exception $e)
@ -50,7 +50,7 @@ class mod_syslog_firephp extends LogHandler implements LogHandlerInterface
print '<!-- FirePHP no available into PHP -->'."\n";
}
return false;
return -1;
}
// /**
@ -59,7 +59,7 @@ class mod_syslog_firephp extends LogHandler implements LogHandlerInterface
// public function configure()
// {
// global $langs;
// return array(
// array(
// 'name' => $langs->trans('IncludePath'),
@ -86,7 +86,7 @@ class mod_syslog_firephp extends LogHandler implements LogHandlerInterface
{
$errors[] = $langs->trans("ErrorFailedToOpenFile", 'FirePhp.php');
}
set_include_path($oldinclude);
return $errors;

View File

@ -38,10 +38,10 @@ class mod_syslog_syslog extends LogHandler implements LogHandlerInterface
// This function does not exists on some ISP (Ex: Free in France)
if (!function_exists('openlog'))
{
return false;
return 0;
}
return true;
return 1;
}
/**
@ -66,7 +66,7 @@ class mod_syslog_syslog extends LogHandler implements LogHandlerInterface
public function checkConfiguration()
{
global $langs;
$errors = array();
$facility = SYSLOG_FACILITY;
@ -81,10 +81,10 @@ class mod_syslog_syslog extends LogHandler implements LogHandlerInterface
{
$errors[] = $langs->trans("ErrorUnknownSyslogConstant", $facility);
}
return $errors;
}
/**
* Export the message
* @param array $content Array containing the info about the message

View File

@ -911,6 +911,7 @@ TranslationSetup=Configuration de la traduction
TranslationDesc=Choice of language visible on screen can be modified:<br>* Globally from menu <strong>Home - Setup - Display</strong><br>* For user only from tab <strong>User display</strong> of user card (click on login on top of screen).
TotalNumberOfActivatedModules=Total number of activated feature modules: <b>%s</b>
YouMustEnableOneModule=You must at least enable 1 module
ClassNotFoundIntoPathWarning=Class %s not found into PHP path
##### Module password generation
PasswordGenerationStandard=Return a password generated according to internal Dolibarr algorithm: 8 characters containing shared numbers and characters in lowercase.

View File

@ -918,6 +918,8 @@ PathDirectory= Répertoire
SendmailOptionMayHurtBuggedMTA=La fonction d'envoi de mails par la méthode "PHP mail directe" génère une requete mail qui peut être mal interprété par certains serveurs buggués de réception de mail. Cela se traduit par des mails non lisibles chez les personnes hebergés par ces plateformes bugguées. C'est le cas des clients de certains fournisseurs d'accès internet (Ex: Orange). Ce n'est pas un problème ni dans Dolibarr ni dans PHP mais sur le serveur de réception. Vous pouvez toutefois ajouter l'option MAIN_FIX_FOR_BUGGED_MTA à 1 dans configuration - divers pour modifier Dolibarr afin de compenser le bug. Toutefois ce sont les serveurs respectueux du standard d'envoi de mail qui pourront avoir des problèmes. L'autre solution (recommandée) est d'utiliser la méthode d'envoi SMTP socket library qui n'a aucun de ces inconvénients.
TranslationSetup=Translation setup
TranslationDesc=Le choix de la langue affichée à l'écran se modifie:<br>* Soit de manière globale depuis le menu <strong>Accueil - Configuration - Affichage</strong><br>* Soit de manière spécifique à l'utilisateur depuis l'onglet <strong>Interface utilisateur</strong> de sa fiche utilisateur (cliquer sur le login en haut de l'écran).
ClassNotFoundIntoPathWarning=La class %s n'a pas été trouvée dans le path PHP
##### Module password generation= undefined
PasswordGenerationStandard= Renvoie un mot de passe généré selon algorithme interne Dolibarr: 8 caractères, chiffres et caractères en minuscules mélangés.
PasswordGenerationNone= Ne propose pas de mots de passe générés. Le mot de passe est à saisir manuellement.