normalize Tlog in english
This commit is contained in:
@@ -40,20 +40,20 @@ abstract class AbstractTlogDestination
|
||||
$this->_logs = array();
|
||||
|
||||
// Initialiser les variables de configuration
|
||||
$this->_configs = $this->get_configs();
|
||||
$this->_configs = $this->getConfigs();
|
||||
|
||||
// Appliquer la configuration
|
||||
$this->configurer();
|
||||
$this->configure();
|
||||
}
|
||||
|
||||
//Affecte une valeur à une configuration de la destination
|
||||
public function set_config($name, $value)
|
||||
public function setConfig($name, $value)
|
||||
{
|
||||
foreach ($this->_configs as $config) {
|
||||
if ($config->name == $name) {
|
||||
$config->value = $value;
|
||||
// Appliquer les changements
|
||||
$this->configurer();
|
||||
$this->configure();
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -63,7 +63,7 @@ abstract class AbstractTlogDestination
|
||||
}
|
||||
|
||||
//Récupère la valeur affectée à une configuration de la destination
|
||||
public function get_config($name)
|
||||
public function getConfig($name)
|
||||
{
|
||||
foreach ($this->_configs as $config) {
|
||||
if ($config->name == $name) {
|
||||
@@ -74,23 +74,23 @@ abstract class AbstractTlogDestination
|
||||
return false;
|
||||
}
|
||||
|
||||
public function get_configs()
|
||||
public function getConfigs()
|
||||
{
|
||||
return $this->_configs;
|
||||
}
|
||||
|
||||
public function mode_back_office($bool)
|
||||
public function SetBackOfficeMode($bool)
|
||||
{
|
||||
$this->flag_back_office = $bool;
|
||||
}
|
||||
|
||||
//Ajoute une ligne de logs à la destination
|
||||
public function ajouter($string)
|
||||
public function add($string)
|
||||
{
|
||||
$this->_logs[] = $string;
|
||||
}
|
||||
|
||||
protected function inserer_apres_body(&$res, $logdata)
|
||||
protected function InsertAfterBody(&$res, $logdata)
|
||||
{
|
||||
$match = array();
|
||||
|
||||
@@ -104,18 +104,18 @@ abstract class AbstractTlogDestination
|
||||
// Demande à la destination de se configurer pour être prête
|
||||
// a fonctionner. Si $config est != false, celà indique
|
||||
// que seul le paramètre de configuration indiqué a été modifié.
|
||||
protected function configurer()
|
||||
protected function configure()
|
||||
{
|
||||
// Cette methode doit etre surchargée si nécessaire.
|
||||
}
|
||||
|
||||
//Lance l'écriture de tous les logs par la destination
|
||||
//$res : contenu de la page html
|
||||
abstract public function ecrire(&$res);
|
||||
abstract public function write(&$res);
|
||||
|
||||
// Retourne le titre de cette destination, tel qu'affiché dans le menu de selection
|
||||
abstract public function get_titre();
|
||||
abstract public function getTitle();
|
||||
|
||||
// Retourne une brève description de la destination
|
||||
abstract public function get_description();
|
||||
abstract public function getDescription();
|
||||
}
|
||||
|
||||
@@ -45,10 +45,10 @@ class TlogDestinationFile extends AbstractTlogDestination
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function configurer()
|
||||
public function configure()
|
||||
{
|
||||
$file_path = $this->get_config(self::VAR_PATH_FILE);
|
||||
$mode = strtolower($this->get_config(self::VAR_MODE)) == 'a' ? 'a' : 'w';
|
||||
$file_path = $this->getConfig(self::VAR_PATH_FILE);
|
||||
$mode = strtolower($this->getConfig(self::VAR_MODE)) == 'a' ? 'a' : 'w';
|
||||
|
||||
if (! empty($file_path)) {
|
||||
if (! is_file($file_path)) {
|
||||
@@ -64,17 +64,17 @@ class TlogDestinationFile extends AbstractTlogDestination
|
||||
}
|
||||
}
|
||||
|
||||
public function get_titre()
|
||||
public function getTitle()
|
||||
{
|
||||
return "Text File";
|
||||
}
|
||||
|
||||
public function get_description()
|
||||
public function getDescription()
|
||||
{
|
||||
return "Store logs into text file";
|
||||
}
|
||||
|
||||
public function get_configs()
|
||||
public function getConfigs()
|
||||
{
|
||||
return array(
|
||||
new TlogDestinationConfig(
|
||||
@@ -94,14 +94,14 @@ class TlogDestinationFile extends AbstractTlogDestination
|
||||
);
|
||||
}
|
||||
|
||||
public function ajouter($texte)
|
||||
public function add($texte)
|
||||
{
|
||||
if ($this->fh) {
|
||||
fwrite($this->fh, $texte."\n");
|
||||
}
|
||||
}
|
||||
|
||||
public function ecrire(&$res)
|
||||
public function write(&$res)
|
||||
{
|
||||
if ($this->fh) @fclose($this->fh);
|
||||
|
||||
|
||||
@@ -27,51 +27,50 @@ use Thelia\Log\AbstractTlogDestination;
|
||||
|
||||
class TlogDestinationHtml extends AbstractTlogDestination
|
||||
{
|
||||
// Nom des variables de configuration
|
||||
// ----------------------------------
|
||||
const VAR_STYLE = "tlog_destinationhtml_style";
|
||||
const VALEUR_STYLE_DEFAUT = "text-align: left; font-size: 12px; font-weight: normal; line-height: 14px; float: none; display:block; color: #000; background-color: #fff; font-family: Courier New, courier,fixed;";
|
||||
// Nom des variables de configuration
|
||||
// ----------------------------------
|
||||
const VAR_STYLE = "tlog_destinationhtml_style";
|
||||
const VALEUR_STYLE_DEFAUT = "text-align: left; font-size: 12px; font-weight: normal; line-height: 14px; float: none; display:block; color: #000; background-color: #fff; font-family: Courier New, courier,fixed;";
|
||||
|
||||
private $style;
|
||||
private $style;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
}
|
||||
|
||||
public function configurer()
|
||||
{
|
||||
$this->style = $this->get_config(self::VAR_STYLE);
|
||||
}
|
||||
|
||||
public function get_titre()
|
||||
{
|
||||
return "Affichage direct dans la page, en HTML";
|
||||
}
|
||||
|
||||
public function get_description()
|
||||
{
|
||||
return "Permet d'afficher les logs directement dans la page resultat, avec une mise en forme HTML.";
|
||||
}
|
||||
|
||||
public function get_configs()
|
||||
{
|
||||
return array(
|
||||
new TlogDestinationConfig(
|
||||
self::VAR_STYLE,
|
||||
"Style d'affichage direct dans la page",
|
||||
"Vous pouvez aussi laisser ce champ vide, et créer un style \"tlog-trace\" dans votre feuille de style.",
|
||||
self::VALEUR_STYLE_DEFAUT,
|
||||
TlogDestinationConfig::TYPE_TEXTAREA
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function ecrire(&$res)
|
||||
public function __construct()
|
||||
{
|
||||
$block = sprintf('<pre class="tlog-trace" style="%s">%s</pre>', $this->style, htmlspecialchars(implode("\n", $this->_logs)));
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
$this->inserer_apres_body($res, $block);
|
||||
public function configure()
|
||||
{
|
||||
$this->style = $this->getConfig(self::VAR_STYLE);
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return "Affichage direct dans la page, en HTML";
|
||||
}
|
||||
|
||||
public function getDescription()
|
||||
{
|
||||
return "Permet d'afficher les logs directement dans la page resultat, avec une mise en forme HTML.";
|
||||
}
|
||||
|
||||
public function getConfigs()
|
||||
{
|
||||
return array(
|
||||
new TlogDestinationConfig(
|
||||
self::VAR_STYLE,
|
||||
"Style d'affichage direct dans la page",
|
||||
"Vous pouvez aussi laisser ce champ vide, et créer un style \"tlog-trace\" dans votre feuille de style.",
|
||||
self::VALEUR_STYLE_DEFAUT,
|
||||
TlogDestinationConfig::TYPE_TEXTAREA
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function write(&$res)
|
||||
{
|
||||
$block = sprintf('<pre class="tlog-trace" style="%s">%s</pre>', $this->style, htmlspecialchars(implode("\n", $this->_logs)));
|
||||
|
||||
$this->InsertAfterBody($res, $block);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ use Thelia\Model\ConfigQuery;
|
||||
* Allow to define different level and output.
|
||||
*
|
||||
* @author Franck Allimant <franck@cqfdev.fr>
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class Tlog Implements TlogInterface
|
||||
{
|
||||
@@ -72,7 +73,7 @@ class Tlog Implements TlogInterface
|
||||
|
||||
private $linecount = 0;
|
||||
|
||||
protected static $ecrire_effectue = false;
|
||||
protected static $done = false;
|
||||
|
||||
// directories where are the Destinations Files
|
||||
public $dir_destinations = array();
|
||||
@@ -89,92 +90,93 @@ class Tlog Implements TlogInterface
|
||||
* @return \Thelia\Log\Tlog
|
||||
*/
|
||||
public static function instance() {
|
||||
if (self::$instance == false) {
|
||||
self::$instance = new Tlog();
|
||||
if (self::$instance == false) {
|
||||
self::$instance = new Tlog();
|
||||
|
||||
// On doit placer les initialisations à ce level pour pouvoir
|
||||
// utiliser la classe Tlog dans les classes de base (Cnx, BaseObj, etc.)
|
||||
// Les placer dans le constructeur provoquerait une boucle
|
||||
self::$instance->init();
|
||||
}
|
||||
// On doit placer les initialisations à ce level pour pouvoir
|
||||
// utiliser la classe Tlog dans les classes de base (Cnx, BaseObj, etc.)
|
||||
// Les placer dans le constructeur provoquerait une boucle
|
||||
self::$instance->init();
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
protected function init()
|
||||
{
|
||||
|
||||
$this->set_level(ConfigQuery::read(self::VAR_LEVEL, self::DEFAULT_LEVEL));
|
||||
$this->setLevel(ConfigQuery::read(self::VAR_LEVEL, self::DEFAULT_LEVEL));
|
||||
|
||||
$this->dir_destinations = array(
|
||||
__DIR__.'/Destination'
|
||||
//, __DIR__.'/../client/tlog/destinations'
|
||||
);
|
||||
$this->dir_destinations = array(
|
||||
__DIR__.'/Destination'
|
||||
//, __DIR__.'/../client/tlog/destinations'
|
||||
);
|
||||
|
||||
$this->set_prefixe(ConfigQuery::read(self::VAR_PREFIXE, self::DEFAUT_PREFIXE));
|
||||
$this->set_files(ConfigQuery::read(self::VAR_FILES, self::DEFAUT_FILES));
|
||||
$this->set_ip(ConfigQuery::read(self::VAR_IP, self::DEFAUT_IP));
|
||||
$this->set_destinations(ConfigQuery::read(self::VAR_DESTINATIONS, self::DEFAUT_DESTINATIONS));
|
||||
$this->set_show_redirect(ConfigQuery::read(self::VAR_SHOW_REDIRECT, self::DEFAUT_SHOW_REDIRECT));
|
||||
$this->setPrefix(ConfigQuery::read(self::VAR_PREFIXE, self::DEFAUT_PREFIXE));
|
||||
$this->setFiles(ConfigQuery::read(self::VAR_FILES, self::DEFAUT_FILES));
|
||||
$this->setIp(ConfigQuery::read(self::VAR_IP, self::DEFAUT_IP));
|
||||
$this->setDestinations(ConfigQuery::read(self::VAR_DESTINATIONS, self::DEFAUT_DESTINATIONS));
|
||||
$this->setShowRedirect(ConfigQuery::read(self::VAR_SHOW_REDIRECT, self::DEFAUT_SHOW_REDIRECT));
|
||||
|
||||
// Au cas ou il y aurait un exit() quelque part dans le code.
|
||||
register_shutdown_function(array($this, 'ecrire_si_exit'));
|
||||
// Au cas ou il y aurait un exit() quelque part dans le code.
|
||||
register_shutdown_function(array($this, 'writeOnExit'));
|
||||
}
|
||||
|
||||
// Configuration
|
||||
// -------------
|
||||
|
||||
public function set_destinations($destinations)
|
||||
public function setDestinations($destinations)
|
||||
{
|
||||
if (! empty($destinations)) {
|
||||
if (! empty($destinations)) {
|
||||
|
||||
$this->destinations = array();
|
||||
$this->destinations = array();
|
||||
|
||||
$classes_destinations = explode(';', $destinations);
|
||||
$this->loadDestinations($this->destinations, $classes_destinations);
|
||||
}
|
||||
$classes_destinations = explode(';', $destinations);
|
||||
$this->loadDestinations($this->destinations, $classes_destinations);
|
||||
}
|
||||
}
|
||||
|
||||
public function set_level($level)
|
||||
public function setLevel($level)
|
||||
{
|
||||
$this->level = $level;
|
||||
}
|
||||
|
||||
public function set_prefixe($prefixe)
|
||||
public function setPrefix($prefixe)
|
||||
{
|
||||
$this->prefixe = $prefixe;
|
||||
}
|
||||
|
||||
public function set_files($files)
|
||||
public function setFiles($files)
|
||||
{
|
||||
$this->files = explode(";", $files);
|
||||
|
||||
$this->all_files = in_array('*', $this->files);
|
||||
}
|
||||
|
||||
public function set_ip($ips)
|
||||
public function setIp($ips)
|
||||
{
|
||||
if (! empty($ips) && ! in_array($_SERVER['REMOTE_ADDR'], explode(";", $ips))) $this->level = self::MUET;
|
||||
// isset($_SERVER['REMOTE_ADDR']) if we are in cli mode
|
||||
if (! empty($ips) && isset($_SERVER['REMOTE_ADDR']) && ! in_array($_SERVER['REMOTE_ADDR'], explode(";", $ips))) $this->level = self::MUET;
|
||||
}
|
||||
|
||||
public function set_show_redirect($bool)
|
||||
public function setShowRedirect($bool)
|
||||
{
|
||||
$this->show_redirect = $bool;
|
||||
}
|
||||
|
||||
// Configuration d'une destination
|
||||
public function set_config($destination, $param, $valeur)
|
||||
public function setConfig($destination, $param, $valeur)
|
||||
{
|
||||
if (isset($this->destinations[$destination])) {
|
||||
$this->destinations[$destination]->set_config($param, $valeur);
|
||||
$this->destinations[$destination]->setConfig($param, $valeur);
|
||||
}
|
||||
}
|
||||
|
||||
// Configuration d'une destination
|
||||
public function get_config($destination, $param)
|
||||
public function getConfig($destination, $param)
|
||||
{
|
||||
if (isset($this->destinations[$destination])) {
|
||||
return $this->destinations[$destination]->get_config($param);
|
||||
return $this->destinations[$destination]->getConfig($param);
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -244,40 +246,41 @@ class Tlog Implements TlogInterface
|
||||
}
|
||||
|
||||
// Mode back office
|
||||
public static function mode_back_office($booleen)
|
||||
public static function SetBackOfficeMode($booleen)
|
||||
{
|
||||
foreach (Tlog::instance()->destinations as $dest) {
|
||||
$dest->mode_back_office($booleen);
|
||||
$dest->SetBackOfficeMode($booleen);
|
||||
}
|
||||
}
|
||||
|
||||
// Ecriture finale
|
||||
public function ecrire(&$res)
|
||||
public function write(&$res)
|
||||
{
|
||||
self::$ecrire_effectue = true;
|
||||
self::$done = true;
|
||||
|
||||
// Muet ? On ne fait rien
|
||||
if ($this->level == self::MUET) return;
|
||||
|
||||
foreach ($this->destinations as $dest) {
|
||||
$dest->ecrire($res);
|
||||
$dest->write($res);
|
||||
}
|
||||
}
|
||||
|
||||
public function ecrire_si_exit()
|
||||
//function register into register shutdown function stack
|
||||
public function writeOnExit()
|
||||
{
|
||||
// Si les infos de debug n'ont pas été ecrites, le faire maintenant
|
||||
if (self::$ecrire_effectue === false) {
|
||||
if (self::$done === false) {
|
||||
|
||||
$res = "";
|
||||
|
||||
$this->ecrire($res);
|
||||
$this->write($res);
|
||||
|
||||
echo $res;
|
||||
}
|
||||
}
|
||||
|
||||
public function afficher_redirections($url)
|
||||
public function showRedirect($url)
|
||||
{
|
||||
if ($this->level != self::MUET && $this->show_redirect) {
|
||||
echo "
|
||||
@@ -297,15 +300,15 @@ class Tlog Implements TlogInterface
|
||||
|
||||
// Permet de déterminer si la trace est active, en prenant en compte
|
||||
// le level et le filtrage par fichier
|
||||
public function active($level)
|
||||
public function isActivated($level)
|
||||
{
|
||||
if ($this->level <= $level) {
|
||||
|
||||
$origine = $this->trouver_origine();
|
||||
$origin = $this->findOrigin();
|
||||
|
||||
$file = basename($origine['file']);
|
||||
$file = basename($origin['file']);
|
||||
|
||||
if ($this->is_file_active($file)) {
|
||||
if ($this->isActivedFile($file)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -313,7 +316,7 @@ class Tlog Implements TlogInterface
|
||||
return false;
|
||||
}
|
||||
|
||||
public function is_file_active($file)
|
||||
public function isActivedFile($file)
|
||||
{
|
||||
return ($this->all_files || in_array($file, $this->files)) && ! in_array("!$file", $this->files);
|
||||
}
|
||||
@@ -321,7 +324,7 @@ class Tlog Implements TlogInterface
|
||||
/* -- Methodes privees ---------------------------------------- */
|
||||
|
||||
// Adapté de LoggerLoginEvent dans log4php
|
||||
private function trouver_origine()
|
||||
private function findOrigin()
|
||||
{
|
||||
$origine = array();
|
||||
|
||||
@@ -372,11 +375,11 @@ class Tlog Implements TlogInterface
|
||||
$text .= is_scalar($arg) ? $arg : print_r($arg, true);
|
||||
}
|
||||
|
||||
$origine = $this->trouver_origine();
|
||||
$origine = $this->findOrigin();
|
||||
|
||||
$file = basename($origine['file']);
|
||||
|
||||
if ($this->is_file_active($file)) {
|
||||
if ($this->isActivedFile($file)) {
|
||||
|
||||
$function = $origine['function'];
|
||||
$line = $origine['line'];
|
||||
@@ -390,7 +393,7 @@ class Tlog Implements TlogInterface
|
||||
$trace = $prefixe . $text;
|
||||
|
||||
foreach ($this->destinations as $dest) {
|
||||
$dest->ajouter($trace);
|
||||
$dest->add($trace);
|
||||
}
|
||||
|
||||
$this->linecount++;
|
||||
|
||||
Reference in New Issue
Block a user