put copyright in head files and create abstract log destination class
This commit is contained in:
113
core/lib/Thelia/Log/AbstractTlogDestination.php
Normal file
113
core/lib/Thelia/Log/AbstractTlogDestination.php
Normal file
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* 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, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Log;
|
||||
|
||||
abstract class AbstractTlogDestination {
|
||||
|
||||
//Tableau de TlogDestinationConfig paramétrant la destination
|
||||
protected $_configs;
|
||||
|
||||
//Tableau des lignes de logs stockés avant utilisation par ecrire()
|
||||
protected $_logs;
|
||||
|
||||
// Vaudra true si on est dans le back office.
|
||||
protected $flag_back_office = false;
|
||||
|
||||
public function __construct() {
|
||||
$this->_configs = array();
|
||||
$this->_logs = array();
|
||||
|
||||
// Initialiser les variables de configuration
|
||||
$this->_configs = $this->get_configs();
|
||||
|
||||
// Appliquer la configuration
|
||||
$this->configurer();
|
||||
}
|
||||
|
||||
//Affecte une valeur à une configuration de la destination
|
||||
public function set_config($nom, $valeur) {
|
||||
foreach($this->_configs as $config) {
|
||||
if($config->nom == $nom) {
|
||||
$config->valeur = $valeur;
|
||||
// Appliquer les changements
|
||||
$this->configurer($config);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//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) {
|
||||
return $config->valeur;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function get_configs() {
|
||||
return $this->_configs;
|
||||
}
|
||||
|
||||
public function mode_back_office($bool) {
|
||||
$this->flag_back_office = $bool;
|
||||
}
|
||||
|
||||
//Ajoute une ligne de logs à la destination
|
||||
public function ajouter($string) {
|
||||
$this->_logs[] = $string;
|
||||
}
|
||||
|
||||
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 {
|
||||
$res = $logdata . $res;
|
||||
}
|
||||
}
|
||||
|
||||
// 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) {
|
||||
// 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);
|
||||
|
||||
// Retourne le titre de cette destination, tel qu'affiché dans le menu de selection
|
||||
abstract public function get_titre();
|
||||
|
||||
// Retourne une brève description de la destination
|
||||
abstract public function get_description();
|
||||
}
|
||||
@@ -1,20 +1,48 @@
|
||||
<?php
|
||||
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* 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, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
namespace Thelia\Log;
|
||||
|
||||
use Thelia\Model\Config;
|
||||
|
||||
/**
|
||||
*
|
||||
* Thelia Logger
|
||||
*
|
||||
* Allow to define different level and output.
|
||||
*
|
||||
* @author Franck Allimant <franck@cqfdev.fr>
|
||||
*/
|
||||
class Tlog
|
||||
{
|
||||
// Nom des variables de configuration
|
||||
const VAR_NIVEAU = "tlog_niveau";
|
||||
const VAR_LEVEL = "tlog_level";
|
||||
const VAR_DESTINATIONS = "tlog_destinations";
|
||||
const VAR_PREFIXE = "tlog_prefixe";
|
||||
const VAR_PREFIXE = "tlog_prefix";
|
||||
const VAR_FILES = "tlog_files";
|
||||
const VAR_IP = "tlog_ip";
|
||||
const VAR_SHOW_REDIRECT = "tlog_show_redirect";
|
||||
const VAR_IP = "tlog_ip";
|
||||
const VAR_SHOW_REDIRECT = "tlog_show_redirect";
|
||||
|
||||
// Les differents niveaux de trace
|
||||
// all level of trace
|
||||
const TRACE = 1;
|
||||
const DEBUG = 2;
|
||||
const WARNING = 3;
|
||||
@@ -23,8 +51,8 @@ class Tlog
|
||||
const FATAL = 6;
|
||||
const MUET = PHP_INT_MAX;
|
||||
|
||||
// Valeurs par defaut
|
||||
const DEFAUT_NIVEAU = self::MUET;
|
||||
// default values
|
||||
const DEFAULT_LEVEL = self::MUET;
|
||||
const DEFAUT_DESTINATIONS = "Thelia\Log\Destination\TlogDestinationHtml";
|
||||
const DEFAUT_PREFIXE = "#NUM: #NIVEAU [#FICHIER:#FONCTION()] {#LIGNE} #DATE #HEURE: ";
|
||||
const DEFAUT_FILES = "*";
|
||||
@@ -36,7 +64,7 @@ class Tlog
|
||||
protected $destinations = array();
|
||||
|
||||
protected $mode_back_office = false;
|
||||
protected $niveau = self::MUET;
|
||||
protected $level = self::MUET;
|
||||
protected $prefixe = "";
|
||||
protected $files = array();
|
||||
protected $all_files = false;
|
||||
@@ -46,7 +74,7 @@ class Tlog
|
||||
|
||||
protected static $ecrire_effectue = false;
|
||||
|
||||
// Les repertoires où rechercher les classes destination
|
||||
// directories where are the Destinations Files
|
||||
public $dir_destinations = array();
|
||||
|
||||
public static function instance() {
|
||||
@@ -63,12 +91,12 @@ class Tlog
|
||||
}
|
||||
|
||||
protected function init() {
|
||||
$niveau = Config::read(self::VAR_NIVEAU, self::DEFAUT_NIVEAU);
|
||||
$level = Config::read(self::VAR_LEVEL, self::DEFAULT_LEVEL);
|
||||
|
||||
$this->set_niveau($niveau);
|
||||
$this->set_niveau($level);
|
||||
|
||||
$this->dir_destinations = array(
|
||||
__DIR__.'/tlog/destinations'
|
||||
__DIR__.'/Destination'
|
||||
//, __DIR__.'/../client/tlog/destinations'
|
||||
);
|
||||
|
||||
@@ -85,7 +113,7 @@ class Tlog
|
||||
// Configuration
|
||||
// -------------
|
||||
|
||||
public function set_destinations($destinations) {
|
||||
public function set_destinations(AbstractTlogDestination $destinations) {
|
||||
if (! empty($destinations)) {
|
||||
|
||||
$this->destinations = array();
|
||||
@@ -95,8 +123,8 @@ class Tlog
|
||||
}
|
||||
}
|
||||
|
||||
public function set_niveau($niveau) {
|
||||
$this->niveau = $niveau;
|
||||
public function set_niveau($level) {
|
||||
$this->niveau = $level;
|
||||
}
|
||||
|
||||
public function set_prefixe($prefixe) {
|
||||
@@ -247,9 +275,9 @@ class Tlog
|
||||
|
||||
// Permet de déterminer si la trace est active, en prenant en compte
|
||||
// le niveau et le filtrage par fichier
|
||||
public function active($niveau) {
|
||||
public function active($level) {
|
||||
|
||||
if ($this->niveau <= $niveau) {
|
||||
if ($this->niveau <= $level) {
|
||||
|
||||
$origine = $this->trouver_origine();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user