refactor Thelia logger
This commit is contained in:
@@ -1,31 +1,14 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
require __DIR__ . '/vendor/symfony/class-loader/Symfony/Component/ClassLoader/UniversalClassLoader.php';
|
$loader = require __DIR__ . "/vendor/autoload.php";
|
||||||
require __DIR__ . '/lib/Thelia/Autoload/TheliaUniversalClassLoader.php';
|
|
||||||
require __DIR__ . '/lib/Thelia/Autoload/TheliaApcUniversalClassLoader.php';
|
|
||||||
|
|
||||||
use Thelia\Autoload\TheliaUniversalClassLoader;
|
$loader->add('Thelia', __DIR__ . '/lib/');
|
||||||
use Thelia\Autoload\TheliaApcUniversalClassLoader;
|
|
||||||
|
|
||||||
if (extension_loaded('apc') && $env == 'prod') {
|
if (extension_loaded('apc') && $env == 'prod') {
|
||||||
$loader = new TheliaApcUniversalClassLoader('Thelia');
|
$loader->unregister();
|
||||||
} else {
|
|
||||||
$loader = new TheliaUniversalClassLoader();
|
require __DIR__ . '/vendor/symfony/class-loader/Symfony/Component/ClassLoader/ApcClassLoader.php';
|
||||||
|
|
||||||
|
$apcLoader = new Symfony\Component\ClassLoader\ApcClassLoader("thelia",$loader);
|
||||||
|
$apcLoader->register();
|
||||||
}
|
}
|
||||||
|
|
||||||
$namespaces = require __DIR__ . '/vendor/composer/autoload_namespaces.php';
|
|
||||||
|
|
||||||
foreach ($namespaces as $namespace => $directory) {
|
|
||||||
$loader->registerNamespace($namespace, $directory);
|
|
||||||
}
|
|
||||||
|
|
||||||
$loader->registerNamespace('Thelia', __DIR__ . '/lib/');
|
|
||||||
|
|
||||||
if(file_exists(__DIR__ . '/vendor/composer/autoload_classmap.php'))
|
|
||||||
{
|
|
||||||
$classMap = require __DIR__ . '/vendor/composer/autoload_classmap.php';
|
|
||||||
|
|
||||||
$loader->addClassMap($classMap);
|
|
||||||
}
|
|
||||||
|
|
||||||
$loader->register();
|
|
||||||
|
|||||||
@@ -74,6 +74,9 @@ class Parser implements ParserInterface
|
|||||||
{
|
{
|
||||||
$this->loadParser();
|
$this->loadParser();
|
||||||
|
|
||||||
|
|
||||||
|
\Thelia\Log\Tlog::instance()->debug("tutu");
|
||||||
|
|
||||||
return $this->content;
|
return $this->content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,13 +34,11 @@ abstract class AbstractTlogDestination
|
|||||||
// Vaudra true si on est dans le back office.
|
// Vaudra true si on est dans le back office.
|
||||||
protected $flag_back_office = false;
|
protected $flag_back_office = false;
|
||||||
|
|
||||||
protected $configModel;
|
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->_configs = array();
|
$this->_configs = array();
|
||||||
$this->_logs = array();
|
$this->_logs = array();
|
||||||
|
|
||||||
// Initialiser les variables de configuration
|
// Initialiser les variables de configuration
|
||||||
$this->_configs = $this->get_configs();
|
$this->_configs = $this->get_configs();
|
||||||
|
|
||||||
@@ -49,13 +47,13 @@ abstract class AbstractTlogDestination
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Affecte une valeur à une configuration de la destination
|
//Affecte une valeur à une configuration de la destination
|
||||||
public function set_config($nom, $valeur)
|
public function set_config($name, $value)
|
||||||
{
|
{
|
||||||
foreach ($this->_configs as $config) {
|
foreach ($this->_configs as $config) {
|
||||||
if ($config->nom == $nom) {
|
if ($config->name == $name) {
|
||||||
$config->valeur = $valeur;
|
$config->value = $value;
|
||||||
// Appliquer les changements
|
// Appliquer les changements
|
||||||
$this->configurer($config);
|
$this->configurer();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -64,22 +62,12 @@ abstract class AbstractTlogDestination
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setConfigModel($configModel)
|
|
||||||
{
|
|
||||||
$this->configModel = $configModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getConfigModel()
|
|
||||||
{
|
|
||||||
return $this->configModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Récupère la valeur affectée à une configuration de la destination
|
//Récupère la valeur affectée à une configuration de la destination
|
||||||
public function get_config($nom)
|
public function get_config($name)
|
||||||
{
|
{
|
||||||
foreach ($this->_configs as $config) {
|
foreach ($this->_configs as $config) {
|
||||||
if ($config->nom == $nom) {
|
if ($config->name == $name) {
|
||||||
return $config->valeur;
|
return $config->value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,7 +104,7 @@ abstract class AbstractTlogDestination
|
|||||||
// Demande à la destination de se configurer pour être prête
|
// Demande à la destination de se configurer pour être prête
|
||||||
// a fonctionner. Si $config est != false, celà indique
|
// a fonctionner. Si $config est != false, celà indique
|
||||||
// que seul le paramètre de configuration indiqué a été modifié.
|
// que seul le paramètre de configuration indiqué a été modifié.
|
||||||
protected function configurer($config = false)
|
protected function configurer()
|
||||||
{
|
{
|
||||||
// Cette methode doit etre surchargée si nécessaire.
|
// Cette methode doit etre surchargée si nécessaire.
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,19 +34,18 @@ class TlogDestinationFile extends AbstractTlogDestination
|
|||||||
const TLOG_DEFAULT_NAME = "log-thelia.txt";
|
const TLOG_DEFAULT_NAME = "log-thelia.txt";
|
||||||
|
|
||||||
const VAR_MODE = "tlog_destinationfile_mode";
|
const VAR_MODE = "tlog_destinationfile_mode";
|
||||||
const VALEUR_MODE_DEFAUT = "A";
|
const VALEUR_MODE_DEFAULT = "A";
|
||||||
|
|
||||||
protected $path_defaut = false;
|
protected $path_defaut = false;
|
||||||
protected $fh = false;
|
protected $fh = false;
|
||||||
|
|
||||||
public function __construct($configModel = null)
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->path_defaut = THELIA_ROOT . "log/" . self::TLOG_DEFAULT_NAME;
|
$this->path_defaut = THELIA_ROOT . "log/" . self::TLOG_DEFAULT_NAME;
|
||||||
$this->setConfigModel($configModel);
|
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function configurer($config = false)
|
public function configurer()
|
||||||
{
|
{
|
||||||
$file_path = $this->get_config(self::VAR_PATH_FILE);
|
$file_path = $this->get_config(self::VAR_PATH_FILE);
|
||||||
$mode = strtolower($this->get_config(self::VAR_MODE)) == 'a' ? 'a' : 'w';
|
$mode = strtolower($this->get_config(self::VAR_MODE)) == 'a' ? 'a' : 'w';
|
||||||
@@ -83,16 +82,14 @@ class TlogDestinationFile extends AbstractTlogDestination
|
|||||||
"Chemin du fichier",
|
"Chemin du fichier",
|
||||||
"Attention, vous devez indiquer un chemin absolu.<br />Le répertoire de base de votre Thelia est ".dirname(getcwd()),
|
"Attention, vous devez indiquer un chemin absolu.<br />Le répertoire de base de votre Thelia est ".dirname(getcwd()),
|
||||||
$this->path_defaut,
|
$this->path_defaut,
|
||||||
TlogDestinationConfig::TYPE_TEXTFIELD,
|
TlogDestinationConfig::TYPE_TEXTFIELD
|
||||||
$this->getConfigModel()
|
|
||||||
),
|
),
|
||||||
new TlogDestinationConfig(
|
new TlogDestinationConfig(
|
||||||
self::VAR_MODE,
|
self::VAR_MODE,
|
||||||
"Mode d'ouverture (A ou E)",
|
"Mode d'ouverture (A ou E)",
|
||||||
"Indiquez E pour ré-initialiser le fichier à chaque requête, A pour ne jamais réinitialiser le fichier. Pensez à le vider de temps en temps !",
|
"Indiquez E pour ré-initialiser le fichier à chaque requête, A pour ne jamais réinitialiser le fichier. Pensez à le vider de temps en temps !",
|
||||||
self::VALEUR_MODE_DEFAUT,
|
self::VALEUR_MODE_DEFAULT,
|
||||||
TlogDestinationConfig::TYPE_TEXTFIELD,
|
TlogDestinationConfig::TYPE_TEXTFIELD
|
||||||
$this->getConfigModel()
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ class TlogDestinationHtml extends AbstractTlogDestination
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function configurer($config = false)
|
public function configurer()
|
||||||
{
|
{
|
||||||
$this->style = $this->get_config(self::VAR_STYLE);
|
$this->style = $this->get_config(self::VAR_STYLE);
|
||||||
}
|
}
|
||||||
@@ -57,15 +57,15 @@ class TlogDestinationHtml extends AbstractTlogDestination
|
|||||||
|
|
||||||
public function get_configs()
|
public function get_configs()
|
||||||
{
|
{
|
||||||
// return array(
|
return array(
|
||||||
// new TlogDestinationConfig(
|
new TlogDestinationConfig(
|
||||||
// self::VAR_STYLE,
|
self::VAR_STYLE,
|
||||||
// "Style d'affichage direct dans la page",
|
"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.",
|
"Vous pouvez aussi laisser ce champ vide, et créer un style \"tlog-trace\" dans votre feuille de style.",
|
||||||
// self::VALEUR_STYLE_DEFAUT,
|
self::VALEUR_STYLE_DEFAUT,
|
||||||
// TlogDestinationConfig::TYPE_TEXTAREA
|
TlogDestinationConfig::TYPE_TEXTAREA
|
||||||
// )
|
)
|
||||||
// );
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function ecrire(&$res)
|
public function ecrire(&$res)
|
||||||
|
|||||||
@@ -22,8 +22,7 @@
|
|||||||
/*************************************************************************************/
|
/*************************************************************************************/
|
||||||
namespace Thelia\Log;
|
namespace Thelia\Log;
|
||||||
|
|
||||||
use Thelia\Model\Config;
|
use Thelia\Model\ConfigQuery;
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -53,7 +52,7 @@ class Tlog Implements TlogInterface
|
|||||||
const MUET = PHP_INT_MAX;
|
const MUET = PHP_INT_MAX;
|
||||||
|
|
||||||
// default values
|
// default values
|
||||||
const DEFAULT_LEVEL = self::DEBUG;
|
const DEFAULT_LEVEL = self::DEBUG;
|
||||||
const DEFAUT_DESTINATIONS = "Thelia\Log\Destination\TlogDestinationFile";
|
const DEFAUT_DESTINATIONS = "Thelia\Log\Destination\TlogDestinationFile";
|
||||||
const DEFAUT_PREFIXE = "#NUM: #NIVEAU [#FICHIER:#FONCTION()] {#LIGNE} #DATE #HEURE: ";
|
const DEFAUT_PREFIXE = "#NUM: #NIVEAU [#FICHIER:#FONCTION()] {#LIGNE} #DATE #HEURE: ";
|
||||||
const DEFAUT_FILES = "*";
|
const DEFAUT_FILES = "*";
|
||||||
@@ -78,52 +77,45 @@ class Tlog Implements TlogInterface
|
|||||||
// directories where are the Destinations Files
|
// directories where are the Destinations Files
|
||||||
public $dir_destinations = array();
|
public $dir_destinations = array();
|
||||||
|
|
||||||
protected $container;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param type $container
|
|
||||||
*
|
|
||||||
* public function __construct(ContainerBuilder $container)
|
|
||||||
*/
|
*/
|
||||||
public function __construct(ContainerInterface $container)
|
private function __construct()
|
||||||
{
|
{
|
||||||
$this->container = $container;
|
|
||||||
|
|
||||||
$this->init();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// public static function instance() {
|
/**
|
||||||
// if (self::$instance == false) {
|
*
|
||||||
// self::$instance = new Tlog();
|
* @return \Thelia\Log\Tlog
|
||||||
//
|
*/
|
||||||
// // On doit placer les initialisations à ce level pour pouvoir
|
public static function instance() {
|
||||||
// // utiliser la classe Tlog dans les classes de base (Cnx, BaseObj, etc.)
|
if (self::$instance == false) {
|
||||||
// // Les placer dans le constructeur provoquerait une boucle
|
self::$instance = new Tlog();
|
||||||
// self::$instance->init();
|
|
||||||
// }
|
// On doit placer les initialisations à ce level pour pouvoir
|
||||||
//
|
// utiliser la classe Tlog dans les classes de base (Cnx, BaseObj, etc.)
|
||||||
// return self::$instance;
|
// Les placer dans le constructeur provoquerait une boucle
|
||||||
// }
|
self::$instance->init();
|
||||||
|
}
|
||||||
|
|
||||||
|
return self::$instance;
|
||||||
|
}
|
||||||
|
|
||||||
protected function init()
|
protected function init()
|
||||||
{
|
{
|
||||||
$config = $this->container->get("model.config");
|
|
||||||
|
|
||||||
$level = $config->read(self::VAR_LEVEL, self::DEFAULT_LEVEL);
|
$this->set_level(ConfigQuery::read(self::VAR_LEVEL, self::DEFAULT_LEVEL));
|
||||||
|
|
||||||
$this->set_level($level);
|
|
||||||
|
|
||||||
$this->dir_destinations = array(
|
$this->dir_destinations = array(
|
||||||
__DIR__.'/Destination'
|
__DIR__.'/Destination'
|
||||||
//, __DIR__.'/../client/tlog/destinations'
|
//, __DIR__.'/../client/tlog/destinations'
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->set_prefixe($config->read(self::VAR_PREFIXE, self::DEFAUT_PREFIXE));
|
$this->set_prefixe(ConfigQuery::read(self::VAR_PREFIXE, self::DEFAUT_PREFIXE));
|
||||||
$this->set_files($config->read(self::VAR_FILES, self::DEFAUT_FILES));
|
$this->set_files(ConfigQuery::read(self::VAR_FILES, self::DEFAUT_FILES));
|
||||||
$this->set_ip($config->read(self::VAR_IP, self::DEFAUT_IP));
|
$this->set_ip(ConfigQuery::read(self::VAR_IP, self::DEFAUT_IP));
|
||||||
$this->set_destinations($config->read(self::VAR_DESTINATIONS, self::DEFAUT_DESTINATIONS));
|
$this->set_destinations(ConfigQuery::read(self::VAR_DESTINATIONS, self::DEFAUT_DESTINATIONS));
|
||||||
$this->set_show_redirect($config->read(self::VAR_SHOW_REDIRECT, self::DEFAUT_SHOW_REDIRECT));
|
$this->set_show_redirect(ConfigQuery::read(self::VAR_SHOW_REDIRECT, self::DEFAUT_SHOW_REDIRECT));
|
||||||
|
|
||||||
// Au cas ou il y aurait un exit() quelque part dans le code.
|
// Au cas ou il y aurait un exit() quelque part dans le code.
|
||||||
register_shutdown_function(array($this, 'ecrire_si_exit'));
|
register_shutdown_function(array($this, 'ecrire_si_exit'));
|
||||||
@@ -345,7 +337,7 @@ class Tlog Implements TlogInterface
|
|||||||
// we are sometimes in functions = no class available: avoid php warning here
|
// we are sometimes in functions = no class available: avoid php warning here
|
||||||
$className = $hop['class'];
|
$className = $hop['class'];
|
||||||
|
|
||||||
if (! empty($className) and ($className == ltrim($this->container->getParameter("logger.class"),'\\') or strtolower(get_parent_class($className)) == ltrim($this->container->getParameter("logger.class"),'\\'))) {
|
if (! empty($className) and ($className == ltrim(__CLASS__,'\\') or strtolower(get_parent_class($className)) == ltrim(__CLASS__,'\\'))) {
|
||||||
$origine['line'] = $hop['line'];
|
$origine['line'] = $hop['line'];
|
||||||
$origine['file'] = $hop['file'];
|
$origine['file'] = $hop['file'];
|
||||||
break;
|
break;
|
||||||
@@ -414,7 +406,7 @@ class Tlog Implements TlogInterface
|
|||||||
{
|
{
|
||||||
foreach ($actives as $active) {
|
foreach ($actives as $active) {
|
||||||
if (class_exists($active)) {
|
if (class_exists($active)) {
|
||||||
$class = new $active($this->container->get('model.config'));
|
$class = new $active();
|
||||||
|
|
||||||
if (!$class instanceof AbstractTlogDestination) {
|
if (!$class instanceof AbstractTlogDestination) {
|
||||||
throw new \UnexpectedValueException($active." must extends Thelia\Tlog\AbstractTlogDestination");
|
throw new \UnexpectedValueException($active." must extends Thelia\Tlog\AbstractTlogDestination");
|
||||||
|
|||||||
@@ -23,41 +23,46 @@
|
|||||||
|
|
||||||
namespace Thelia\Log;
|
namespace Thelia\Log;
|
||||||
|
|
||||||
|
use Thelia\Model\Config;
|
||||||
|
use Thelia\Model\ConfigQuery;
|
||||||
|
|
||||||
class TlogDestinationConfig
|
class TlogDestinationConfig
|
||||||
{
|
{
|
||||||
|
|
||||||
const TYPE_TEXTAREA = 1;
|
const TYPE_TEXTAREA = 1;
|
||||||
const TYPE_TEXTFIELD = 2;
|
const TYPE_TEXTFIELD = 2;
|
||||||
|
|
||||||
public $titre;
|
public $name;
|
||||||
|
public $title;
|
||||||
public $label;
|
public $label;
|
||||||
public $defaut;
|
public $default;
|
||||||
public $type;
|
public $type;
|
||||||
public $valeur;
|
public $value;
|
||||||
|
|
||||||
public function __construct($nom, $titre, $label, $defaut, $type, $config = null)
|
public function __construct($name, $title, $label, $default, $type)
|
||||||
{
|
{
|
||||||
$this->nom = $nom;
|
$this->name = $name;
|
||||||
$this->titre = $titre;
|
$this->title = $title;
|
||||||
$this->label = $label;
|
$this->label = $label;
|
||||||
$this->defaut = $defaut;
|
$this->default = $default;
|
||||||
$this->type = $type;
|
$this->type = $type;
|
||||||
|
|
||||||
// @$this->charger();
|
$this->load();
|
||||||
|
|
||||||
if ($config) {
|
|
||||||
$this->valeur = $config->read($this->nom, $this->defaut);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// public function charger() {
|
|
||||||
// // La variable n'existe pas ? La créer en y affectant la valeur par defaut
|
public function load()
|
||||||
// if (! parent::charger($this->nom)) {
|
{
|
||||||
// $this->valeur = $this->defaut;
|
if (null === $config = ConfigQuery::create()->findOneByName($this->name))
|
||||||
// $this->protege = 1;
|
{
|
||||||
// $this->cache = 1;
|
$config = new Config();
|
||||||
//
|
$config->setName($this->name);
|
||||||
// $this->add();
|
$config->setValue($this->default);
|
||||||
// }
|
$config->setHidden(1);
|
||||||
// }
|
$config->setSecure(1);
|
||||||
|
$config->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->value = $config->getValue();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user