fix some CS
This commit is contained in:
@@ -23,8 +23,8 @@
|
||||
|
||||
namespace Thelia\Log;
|
||||
|
||||
abstract class AbstractTlogDestination {
|
||||
|
||||
abstract class AbstractTlogDestination
|
||||
{
|
||||
//Tableau de TlogDestinationConfig paramétrant la destination
|
||||
protected $_configs;
|
||||
|
||||
@@ -33,14 +33,15 @@ abstract class AbstractTlogDestination {
|
||||
|
||||
// Vaudra true si on est dans le back office.
|
||||
protected $flag_back_office = false;
|
||||
|
||||
|
||||
protected $configModel;
|
||||
|
||||
public function __construct() {
|
||||
public function __construct()
|
||||
{
|
||||
$this->_configs = array();
|
||||
$this->_logs = array();
|
||||
|
||||
// Initialiser les variables de configuration
|
||||
// Initialiser les variables de configuration
|
||||
$this->_configs = $this->get_configs();
|
||||
|
||||
// Appliquer la configuration
|
||||
@@ -48,9 +49,10 @@ abstract class AbstractTlogDestination {
|
||||
}
|
||||
|
||||
//Affecte une valeur à une configuration de la destination
|
||||
public function set_config($nom, $valeur) {
|
||||
foreach($this->_configs as $config) {
|
||||
if($config->nom == $nom) {
|
||||
public function set_config($nom, $valeur)
|
||||
{
|
||||
foreach ($this->_configs as $config) {
|
||||
if ($config->nom == $nom) {
|
||||
$config->valeur = $valeur;
|
||||
// Appliquer les changements
|
||||
$this->configurer($config);
|
||||
@@ -58,50 +60,55 @@ abstract class AbstractTlogDestination {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
public function get_config($nom) {
|
||||
foreach($this->_configs as $config) {
|
||||
if($config->nom == $nom) {
|
||||
public function get_config($nom)
|
||||
{
|
||||
foreach ($this->_configs as $config) {
|
||||
if ($config->nom == $nom) {
|
||||
return $config->valeur;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function get_configs() {
|
||||
public function get_configs()
|
||||
{
|
||||
return $this->_configs;
|
||||
}
|
||||
|
||||
public function mode_back_office($bool) {
|
||||
public function mode_back_office($bool)
|
||||
{
|
||||
$this->flag_back_office = $bool;
|
||||
}
|
||||
|
||||
//Ajoute une ligne de logs à la destination
|
||||
public function ajouter($string) {
|
||||
public function ajouter($string)
|
||||
{
|
||||
$this->_logs[] = $string;
|
||||
}
|
||||
|
||||
protected function inserer_apres_body(&$res, $logdata) {
|
||||
|
||||
protected function inserer_apres_body(&$res, $logdata)
|
||||
{
|
||||
$match = array();
|
||||
|
||||
if (preg_match("/(<body[^>]*>)/i", $res, $match)) {
|
||||
$res = str_replace($match[0], $match[0] . "\n" . $logdata, $res);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$res = $logdata . $res;
|
||||
}
|
||||
}
|
||||
@@ -109,7 +116,8 @@ 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($config = false) {
|
||||
protected function configurer($config = false)
|
||||
{
|
||||
// Cette methode doit etre surchargée si nécessaire.
|
||||
}
|
||||
|
||||
@@ -122,4 +130,4 @@ abstract class AbstractTlogDestination {
|
||||
|
||||
// Retourne une brève description de la destination
|
||||
abstract public function get_description();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,9 +25,9 @@ namespace Thelia\Log\Destination;
|
||||
|
||||
use Thelia\Log\AbstractTlogDestination;
|
||||
use Thelia\Log\TlogDestinationConfig;
|
||||
|
||||
class TlogDestinationFile extends AbstractTlogDestination {
|
||||
|
||||
class TlogDestinationFile extends AbstractTlogDestination
|
||||
{
|
||||
// Nom des variables de configuration
|
||||
// ----------------------------------
|
||||
const VAR_PATH_FILE = "tlog_destinationfile_path";
|
||||
@@ -39,21 +39,22 @@ class TlogDestinationFile extends AbstractTlogDestination {
|
||||
protected $path_defaut = false;
|
||||
protected $fh = false;
|
||||
|
||||
public function __construct($configModel = null) {
|
||||
|
||||
public function __construct($configModel = null)
|
||||
{
|
||||
$this->path_defaut = THELIA_ROOT . "log/" . self::TLOG_DEFAULT_NAME;
|
||||
$this->setConfigModel($configModel);
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function configurer($config = false) {
|
||||
public function configurer($config = false)
|
||||
{
|
||||
$file_path = $this->get_config(self::VAR_PATH_FILE);
|
||||
$mode = strtolower($this->get_config(self::VAR_MODE)) == 'a' ? 'a' : 'w';
|
||||
|
||||
if (! empty($file_path)) {
|
||||
if (! is_file($file_path)) {
|
||||
$dir = dirname($file_path);
|
||||
if(! is_dir($dir)) {
|
||||
if (! is_dir($dir)) {
|
||||
mkdir($dir, 0777, true);
|
||||
}
|
||||
}
|
||||
@@ -64,15 +65,18 @@ class TlogDestinationFile extends AbstractTlogDestination {
|
||||
}
|
||||
}
|
||||
|
||||
public function get_titre() {
|
||||
public function get_titre()
|
||||
{
|
||||
return "Text File";
|
||||
}
|
||||
|
||||
public function get_description() {
|
||||
public function get_description()
|
||||
{
|
||||
return "Store logs into text file";
|
||||
}
|
||||
|
||||
public function get_configs() {
|
||||
public function get_configs()
|
||||
{
|
||||
return array(
|
||||
new TlogDestinationConfig(
|
||||
self::VAR_PATH_FILE,
|
||||
@@ -93,13 +97,15 @@ class TlogDestinationFile extends AbstractTlogDestination {
|
||||
);
|
||||
}
|
||||
|
||||
public function ajouter($texte) {
|
||||
public function ajouter($texte)
|
||||
{
|
||||
if ($this->fh) {
|
||||
fwrite($this->fh, $texte."\n");
|
||||
}
|
||||
}
|
||||
|
||||
public function ecrire(&$res) {
|
||||
public function ecrire(&$res)
|
||||
{
|
||||
if ($this->fh) @fclose($this->fh);
|
||||
|
||||
$this->fh = false;
|
||||
|
||||
@@ -25,8 +25,8 @@ namespace Thelia\Log\Destination;
|
||||
|
||||
use Thelia\Log\AbstractTlogDestination;
|
||||
|
||||
class TlogDestinationHtml extends AbstractTlogDestination {
|
||||
|
||||
class TlogDestinationHtml extends AbstractTlogDestination
|
||||
{
|
||||
// Nom des variables de configuration
|
||||
// ----------------------------------
|
||||
const VAR_STYLE = "tlog_destinationhtml_style";
|
||||
@@ -34,24 +34,29 @@ class TlogDestinationHtml extends AbstractTlogDestination {
|
||||
|
||||
private $style;
|
||||
|
||||
public function __construct() {
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
}
|
||||
|
||||
public function configurer($config = false) {
|
||||
public function configurer($config = false)
|
||||
{
|
||||
$this->style = $this->get_config(self::VAR_STYLE);
|
||||
}
|
||||
|
||||
public function get_titre() {
|
||||
public function get_titre()
|
||||
{
|
||||
return "Affichage direct dans la page, en HTML";
|
||||
}
|
||||
|
||||
public function get_description() {
|
||||
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() {
|
||||
public function get_configs()
|
||||
{
|
||||
// return array(
|
||||
// new TlogDestinationConfig(
|
||||
// self::VAR_STYLE,
|
||||
@@ -63,10 +68,10 @@ class TlogDestinationHtml extends AbstractTlogDestination {
|
||||
// );
|
||||
}
|
||||
|
||||
public function ecrire(&$res) {
|
||||
|
||||
public function ecrire(&$res)
|
||||
{
|
||||
$block = sprintf('<pre class="tlog-trace" style="%s">%s</pre>', $this->style, htmlspecialchars(implode("\n", $this->_logs)));
|
||||
|
||||
$this->inserer_apres_body($res, $block);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,21 +25,25 @@ namespace Thelia\Log\Destination;
|
||||
|
||||
use Thelia\Log\AbstractTlogDestination;
|
||||
|
||||
class TlogDestinationNull extends AbstractTlogDestination {
|
||||
|
||||
public function get_titre() {
|
||||
class TlogDestinationNull extends AbstractTlogDestination
|
||||
{
|
||||
public function get_titre()
|
||||
{
|
||||
return "Trou noir";
|
||||
}
|
||||
|
||||
public function get_description() {
|
||||
public function get_description()
|
||||
{
|
||||
return "Cette destination ne provoque aucune sortie";
|
||||
}
|
||||
|
||||
public function ajouter($string) {
|
||||
public function ajouter($string)
|
||||
{
|
||||
// Rien
|
||||
}
|
||||
|
||||
public function ecrire(&$res) {
|
||||
public function ecrire(&$res)
|
||||
{
|
||||
// Rien
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,26 +25,30 @@ namespace Thelia\Log\Destination;
|
||||
|
||||
use Thelia\Log\AbstractTlogDestination;
|
||||
|
||||
|
||||
class TlogDestinationText extends AbstractTlogDestination {
|
||||
|
||||
public function __construct() {
|
||||
class TlogDestinationText extends AbstractTlogDestination
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function get_titre() {
|
||||
public function get_titre()
|
||||
{
|
||||
return "Affichage direct dans la page, en texte brut";
|
||||
}
|
||||
|
||||
public function get_description() {
|
||||
public function get_description()
|
||||
{
|
||||
return "Permet d'afficher les logs directement dans la page resultat, au format texte brut.";
|
||||
}
|
||||
|
||||
public function ajouter($texte) {
|
||||
public function ajouter($texte)
|
||||
{
|
||||
echo $texte."\n";
|
||||
}
|
||||
|
||||
public function ecrire(&$res) {
|
||||
public function ecrire(&$res)
|
||||
{
|
||||
// Rien
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,11 +26,11 @@ use Thelia\Model\Config;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* Thelia Logger
|
||||
*
|
||||
*
|
||||
* Allow to define different level and output.
|
||||
*
|
||||
*
|
||||
* @author Franck Allimant <franck@cqfdev.fr>
|
||||
*/
|
||||
class Tlog Implements TlogInterface
|
||||
@@ -77,19 +77,19 @@ class Tlog Implements TlogInterface
|
||||
|
||||
// directories where are the Destinations Files
|
||||
public $dir_destinations = array();
|
||||
|
||||
|
||||
protected $container;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param type $container
|
||||
*
|
||||
*
|
||||
* public function __construct(ContainerBuilder $container)
|
||||
*/
|
||||
public function __construct(ContainerInterface $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
|
||||
|
||||
$this->init();
|
||||
}
|
||||
|
||||
@@ -106,9 +106,10 @@ class Tlog Implements TlogInterface
|
||||
// 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($level);
|
||||
@@ -131,7 +132,8 @@ class Tlog Implements TlogInterface
|
||||
// Configuration
|
||||
// -------------
|
||||
|
||||
public function set_destinations($destinations) {
|
||||
public function set_destinations($destinations)
|
||||
{
|
||||
if (! empty($destinations)) {
|
||||
|
||||
$this->destinations = array();
|
||||
@@ -141,40 +143,44 @@ class Tlog Implements TlogInterface
|
||||
}
|
||||
}
|
||||
|
||||
public function set_level($level) {
|
||||
public function set_level($level)
|
||||
{
|
||||
$this->level = $level;
|
||||
}
|
||||
|
||||
public function set_prefixe($prefixe) {
|
||||
|
||||
public function set_prefixe($prefixe)
|
||||
{
|
||||
$this->prefixe = $prefixe;
|
||||
}
|
||||
|
||||
public function set_files($files) {
|
||||
public function set_files($files)
|
||||
{
|
||||
$this->files = explode(";", $files);
|
||||
|
||||
$this->all_files = in_array('*', $this->files);
|
||||
}
|
||||
|
||||
public function set_ip($ips) {
|
||||
public function set_ip($ips)
|
||||
{
|
||||
if (! empty($ips) && ! in_array($_SERVER['REMOTE_ADDR'], explode(";", $ips))) $this->level = self::MUET;
|
||||
}
|
||||
|
||||
public function set_show_redirect($bool) {
|
||||
public function set_show_redirect($bool)
|
||||
{
|
||||
$this->show_redirect = $bool;
|
||||
}
|
||||
|
||||
// Configuration d'une destination
|
||||
public function set_config($destination, $param, $valeur) {
|
||||
|
||||
public function set_config($destination, $param, $valeur)
|
||||
{
|
||||
if (isset($this->destinations[$destination])) {
|
||||
$this->destinations[$destination]->set_config($param, $valeur);
|
||||
}
|
||||
}
|
||||
|
||||
// Configuration d'une destination
|
||||
public function get_config($destination, $param) {
|
||||
|
||||
public function get_config($destination, $param)
|
||||
{
|
||||
if (isset($this->destinations[$destination])) {
|
||||
return $this->destinations[$destination]->get_config($param);
|
||||
}
|
||||
@@ -185,7 +191,8 @@ class Tlog Implements TlogInterface
|
||||
// Methodes d'accès aux traces
|
||||
// ---------------------------
|
||||
|
||||
public function trace() {
|
||||
public function trace()
|
||||
{
|
||||
if ($this->level > self::TRACE)
|
||||
return;
|
||||
|
||||
@@ -194,7 +201,8 @@ class Tlog Implements TlogInterface
|
||||
$this->out("TRACE", $args);
|
||||
}
|
||||
|
||||
public function debug() {
|
||||
public function debug()
|
||||
{
|
||||
if ($this->level > self::DEBUG)
|
||||
return;
|
||||
|
||||
@@ -203,7 +211,8 @@ class Tlog Implements TlogInterface
|
||||
$this->out("DEBUG", $args);
|
||||
}
|
||||
|
||||
public function info() {
|
||||
public function info()
|
||||
{
|
||||
if ($this->level > self::INFO)
|
||||
return;
|
||||
|
||||
@@ -212,7 +221,8 @@ class Tlog Implements TlogInterface
|
||||
$this->out("INFO", $args);
|
||||
}
|
||||
|
||||
public function warning() {
|
||||
public function warning()
|
||||
{
|
||||
if ($this->level > self::WARNING)
|
||||
return;
|
||||
|
||||
@@ -221,7 +231,8 @@ class Tlog Implements TlogInterface
|
||||
$this->out("WARNING", $args);
|
||||
}
|
||||
|
||||
public function error() {
|
||||
public function error()
|
||||
{
|
||||
if ($this->level > self::ERROR)
|
||||
return;
|
||||
|
||||
@@ -230,7 +241,8 @@ class Tlog Implements TlogInterface
|
||||
$this->out("ERREUR", $args);
|
||||
}
|
||||
|
||||
public function fatal() {
|
||||
public function fatal()
|
||||
{
|
||||
if ($this->level > self::FATAL)
|
||||
return;
|
||||
|
||||
@@ -240,27 +252,28 @@ class Tlog Implements TlogInterface
|
||||
}
|
||||
|
||||
// Mode back office
|
||||
public static function mode_back_office($booleen) {
|
||||
|
||||
foreach(Tlog::instance()->destinations as $dest) {
|
||||
public static function mode_back_office($booleen)
|
||||
{
|
||||
foreach (Tlog::instance()->destinations as $dest) {
|
||||
$dest->mode_back_office($booleen);
|
||||
}
|
||||
}
|
||||
|
||||
// Ecriture finale
|
||||
public function ecrire(&$res) {
|
||||
|
||||
public function ecrire(&$res)
|
||||
{
|
||||
self::$ecrire_effectue = true;
|
||||
|
||||
// Muet ? On ne fait rien
|
||||
if ($this->level == self::MUET) return;
|
||||
|
||||
foreach($this->destinations as $dest) {
|
||||
foreach ($this->destinations as $dest) {
|
||||
$dest->ecrire($res);
|
||||
}
|
||||
}
|
||||
|
||||
public function ecrire_si_exit() {
|
||||
public function ecrire_si_exit()
|
||||
{
|
||||
// Si les infos de debug n'ont pas été ecrites, le faire maintenant
|
||||
if (self::$ecrire_effectue === false) {
|
||||
|
||||
@@ -272,8 +285,8 @@ class Tlog Implements TlogInterface
|
||||
}
|
||||
}
|
||||
|
||||
public function afficher_redirections($url) {
|
||||
|
||||
public function afficher_redirections($url)
|
||||
{
|
||||
if ($this->level != self::MUET && $this->show_redirect) {
|
||||
echo "
|
||||
<html>
|
||||
@@ -285,16 +298,15 @@ class Tlog Implements TlogInterface
|
||||
";
|
||||
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// 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 active($level)
|
||||
{
|
||||
if ($this->level <= $level) {
|
||||
|
||||
$origine = $this->trouver_origine();
|
||||
@@ -309,26 +321,27 @@ class Tlog Implements TlogInterface
|
||||
return false;
|
||||
}
|
||||
|
||||
public function is_file_active($file) {
|
||||
public function is_file_active($file)
|
||||
{
|
||||
return ($this->all_files || in_array($file, $this->files)) && ! in_array("!$file", $this->files);
|
||||
}
|
||||
|
||||
/* -- Methodes privees ---------------------------------------- */
|
||||
|
||||
// Adapté de LoggerLoginEvent dans log4php
|
||||
private function trouver_origine() {
|
||||
|
||||
private function trouver_origine()
|
||||
{
|
||||
$origine = array();
|
||||
|
||||
if(function_exists('debug_backtrace')) {
|
||||
if (function_exists('debug_backtrace')) {
|
||||
|
||||
$trace = debug_backtrace();
|
||||
$prevHop = null;
|
||||
// make a downsearch to identify the caller
|
||||
$hop = array_pop($trace);
|
||||
|
||||
while($hop !== null) {
|
||||
if(isset($hop['class'])) {
|
||||
|
||||
while ($hop !== null) {
|
||||
if (isset($hop['class'])) {
|
||||
// we are sometimes in functions = no class available: avoid php warning here
|
||||
$className = $hop['class'];
|
||||
|
||||
@@ -359,8 +372,8 @@ class Tlog Implements TlogInterface
|
||||
return $origine;
|
||||
}
|
||||
|
||||
private function out($level, $tabargs) {
|
||||
|
||||
private function out($level, $tabargs)
|
||||
{
|
||||
$text = '';
|
||||
|
||||
foreach ($tabargs as $arg) {
|
||||
@@ -384,34 +397,31 @@ class Tlog Implements TlogInterface
|
||||
|
||||
$trace = $prefixe . $text;
|
||||
|
||||
foreach($this->destinations as $dest) {
|
||||
foreach ($this->destinations as $dest) {
|
||||
$dest->ajouter($trace);
|
||||
}
|
||||
|
||||
$this->linecount++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param type $destinations
|
||||
* @param array $actives array containing classes instanceof AbstractTlogDestination
|
||||
*
|
||||
* @param type $destinations
|
||||
* @param array $actives array containing classes instanceof AbstractTlogDestination
|
||||
*/
|
||||
protected function loadDestinations(&$destinations, array $actives = NULL) {
|
||||
|
||||
foreach($actives as $active)
|
||||
{
|
||||
if(class_exists($active))
|
||||
{
|
||||
protected function loadDestinations(&$destinations, array $actives = NULL)
|
||||
{
|
||||
foreach ($actives as $active) {
|
||||
if (class_exists($active)) {
|
||||
$class = new $active($this->container->get('model.config'));
|
||||
|
||||
if(!$class instanceof AbstractTlogDestination)
|
||||
{
|
||||
|
||||
if (!$class instanceof AbstractTlogDestination) {
|
||||
throw new \UnexpectedValueException($active." must extends Thelia\Tlog\AbstractTlogDestination");
|
||||
}
|
||||
|
||||
|
||||
$destinations[$active] = $class;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,8 +35,8 @@ class TlogDestinationConfig
|
||||
public $type;
|
||||
public $valeur;
|
||||
|
||||
public function __construct($nom, $titre, $label, $defaut, $type, $config = null) {
|
||||
|
||||
public function __construct($nom, $titre, $label, $defaut, $type, $config = null)
|
||||
{
|
||||
$this->nom = $nom;
|
||||
$this->titre = $titre;
|
||||
$this->label = $label;
|
||||
@@ -44,9 +44,8 @@ class TlogDestinationConfig
|
||||
$this->type = $type;
|
||||
|
||||
// @$this->charger();
|
||||
|
||||
if($config)
|
||||
{
|
||||
|
||||
if ($config) {
|
||||
$this->valeur = $config->read($this->nom, $this->defaut);
|
||||
}
|
||||
}
|
||||
@@ -61,4 +60,4 @@ class TlogDestinationConfig
|
||||
// $this->add();
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,15 +2,14 @@
|
||||
|
||||
namespace Thelia\Log;
|
||||
|
||||
|
||||
Interface TlogInterface
|
||||
{
|
||||
|
||||
|
||||
public function trace();
|
||||
public function debug();
|
||||
public function info();
|
||||
public function warning();
|
||||
public function error();
|
||||
public function fatal();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user