change phpdoc api generator to phpdoc
This commit is contained in:
122
documentation/api/files/Log/AbstractTlogDestination.php.txt
Normal file
122
documentation/api/files/Log/AbstractTlogDestination.php.txt
Normal file
@@ -0,0 +1,122 @@
|
||||
<?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->getConfigs();
|
||||
|
||||
// Appliquer la configuration
|
||||
$this->configure();
|
||||
}
|
||||
|
||||
//Affecte une valeur à une configuration de la destination
|
||||
public function setConfig($name, $value)
|
||||
{
|
||||
foreach ($this->_configs as $config) {
|
||||
if ($config->name == $name) {
|
||||
$config->value = $value;
|
||||
// Appliquer les changements
|
||||
$this->configure();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//Récupère la valeur affectée à une configuration de la destination
|
||||
public function getConfig($name)
|
||||
{
|
||||
foreach ($this->_configs as $config) {
|
||||
if ($config->name == $name) {
|
||||
return $config->value;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getConfigs()
|
||||
{
|
||||
return $this->_configs;
|
||||
}
|
||||
|
||||
public function SetBackOfficeMode($bool)
|
||||
{
|
||||
$this->flag_back_office = $bool;
|
||||
}
|
||||
|
||||
//Ajoute une ligne de logs à la destination
|
||||
public function add($string)
|
||||
{
|
||||
$this->_logs[] = $string;
|
||||
}
|
||||
|
||||
protected function InsertAfterBody(&$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 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 write(&$res);
|
||||
|
||||
// Retourne le titre de cette destination, tel qu'affiché dans le menu de selection
|
||||
abstract public function getTitle();
|
||||
|
||||
// Retourne une brève description de la destination
|
||||
abstract public function getDescription();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
<?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\Destination;
|
||||
|
||||
use Thelia\Log\AbstractTlogDestination;
|
||||
use Thelia\Log\TlogDestinationConfig;
|
||||
|
||||
class TlogDestinationFile extends AbstractTlogDestination
|
||||
{
|
||||
// Nom des variables de configuration
|
||||
// ----------------------------------
|
||||
const VAR_PATH_FILE = "tlog_destinationfile_path";
|
||||
const TLOG_DEFAULT_NAME = "log-thelia.txt";
|
||||
|
||||
const VAR_MODE = "tlog_destinationfile_mode";
|
||||
const VALEUR_MODE_DEFAULT = "A";
|
||||
|
||||
protected $path_defaut = false;
|
||||
protected $fh = false;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->path_defaut = THELIA_ROOT . "log/" . self::TLOG_DEFAULT_NAME;
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function configure()
|
||||
{
|
||||
$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)) {
|
||||
$dir = dirname($file_path);
|
||||
if (! is_dir($dir)) {
|
||||
mkdir($dir, 0777, true);
|
||||
}
|
||||
|
||||
touch($file_path);
|
||||
chmod($file_path, 0777);
|
||||
}
|
||||
|
||||
if ($this->fh) @fclose($this->fh);
|
||||
|
||||
$this->fh = fopen($file_path, $mode);
|
||||
}
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return "Text File";
|
||||
}
|
||||
|
||||
public function getDescription()
|
||||
{
|
||||
return "Store logs into text file";
|
||||
}
|
||||
|
||||
public function getConfigs()
|
||||
{
|
||||
return array(
|
||||
new TlogDestinationConfig(
|
||||
self::VAR_PATH_FILE,
|
||||
"Chemin du fichier",
|
||||
"Attention, vous devez indiquer un chemin absolu.<br />Le répertoire de base de votre Thelia est ".dirname(getcwd()),
|
||||
$this->path_defaut,
|
||||
TlogDestinationConfig::TYPE_TEXTFIELD
|
||||
),
|
||||
new TlogDestinationConfig(
|
||||
self::VAR_MODE,
|
||||
"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 !",
|
||||
self::VALEUR_MODE_DEFAULT,
|
||||
TlogDestinationConfig::TYPE_TEXTFIELD
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function add($texte)
|
||||
{
|
||||
if ($this->fh) {
|
||||
fwrite($this->fh, $texte."\n");
|
||||
}
|
||||
}
|
||||
|
||||
public function write(&$res)
|
||||
{
|
||||
if ($this->fh) @fclose($this->fh);
|
||||
|
||||
$this->fh = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
<?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\Destination;
|
||||
|
||||
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;";
|
||||
|
||||
private $style;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
<?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\Destination;
|
||||
|
||||
use Thelia\Log\AbstractTlogDestination;
|
||||
|
||||
class TlogDestinationNull extends AbstractTlogDestination
|
||||
{
|
||||
public function getTitle()
|
||||
{
|
||||
return "Trou noir";
|
||||
}
|
||||
|
||||
public function getDescription()
|
||||
{
|
||||
return "Cette destination ne provoque aucune sortie";
|
||||
}
|
||||
|
||||
public function add($string)
|
||||
{
|
||||
// Rien
|
||||
}
|
||||
|
||||
public function write(&$res)
|
||||
{
|
||||
// Rien
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
<?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\Destination;
|
||||
|
||||
use Thelia\Log\AbstractTlogDestination;
|
||||
|
||||
class TlogDestinationText extends AbstractTlogDestination
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return "Affichage direct dans la page, en texte brut";
|
||||
}
|
||||
|
||||
public function getDescription()
|
||||
{
|
||||
return "Permet d'afficher les logs directement dans la page resultat, au format texte brut.";
|
||||
}
|
||||
|
||||
public function add($texte)
|
||||
{
|
||||
echo trim($texte)."\n";
|
||||
}
|
||||
|
||||
public function write(&$res)
|
||||
{
|
||||
// Rien
|
||||
}
|
||||
}
|
||||
|
||||
706
documentation/api/files/Log/Tlog.php.txt
Normal file
706
documentation/api/files/Log/Tlog.php.txt
Normal file
@@ -0,0 +1,706 @@
|
||||
<?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\ConfigQuery;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/**
|
||||
*
|
||||
* Thelia Logger
|
||||
*
|
||||
* Allow to define different level and output.
|
||||
*
|
||||
* @author Franck Allimant <franck@cqfdev.fr>
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class Tlog Implements LoggerInterface
|
||||
{
|
||||
// Nom des variables de configuration
|
||||
const VAR_LEVEL = "tlog_level";
|
||||
const VAR_DESTINATIONS = "tlog_destinations";
|
||||
const VAR_PREFIXE = "tlog_prefix";
|
||||
const VAR_FILES = "tlog_files";
|
||||
const VAR_IP = "tlog_ip";
|
||||
const VAR_SHOW_REDIRECT = "tlog_show_redirect";
|
||||
|
||||
// all level of trace
|
||||
const DEBUG = 100;
|
||||
const INFO = 200;
|
||||
const NOTICE = 300;
|
||||
const WARNING = 400;
|
||||
const ERROR = 500;
|
||||
const CRITICAL = 600;
|
||||
const ALERT = 700;
|
||||
const EMERGENCY = 800;
|
||||
const MUET = PHP_INT_MAX;
|
||||
|
||||
protected $levels = array(
|
||||
100 => "DEBUG",
|
||||
200 => "INFO",
|
||||
300 => "NOTICE",
|
||||
400 => "WARNING",
|
||||
500 => "ERROR",
|
||||
600 => "CRITICAL",
|
||||
700 => "ALERT",
|
||||
800 => "EMERGENCY"
|
||||
);
|
||||
|
||||
// default values
|
||||
const DEFAULT_LEVEL = self::DEBUG;
|
||||
const DEFAUT_DESTINATIONS = "Thelia\Log\Destination\TlogDestinationFile";
|
||||
const DEFAUT_PREFIXE = "#NUM: #NIVEAU [#FICHIER:#FONCTION()] {#LIGNE} #DATE #HEURE: ";
|
||||
const DEFAUT_FILES = "*";
|
||||
const DEFAUT_IP = "";
|
||||
const DEFAUT_SHOW_REDIRECT = 0;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var \Thelia\Log\Tlog
|
||||
*/
|
||||
private static $instance = false;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var array containing class of destination handler
|
||||
*/
|
||||
protected $destinations = array();
|
||||
|
||||
protected $mode_back_office = false;
|
||||
protected $level = self::MUET;
|
||||
protected $prefixe = "";
|
||||
protected $files = array();
|
||||
protected $all_files = false;
|
||||
protected $show_redirect = false;
|
||||
|
||||
private $linecount = 0;
|
||||
|
||||
protected static $done = false;
|
||||
|
||||
// directories where are the Destinations Files
|
||||
public $dir_destinations = array();
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function __construct(){}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return \Thelia\Log\Tlog
|
||||
*/
|
||||
public static function getInstance() {
|
||||
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();
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* initialize default configuration
|
||||
*/
|
||||
protected function init()
|
||||
{
|
||||
|
||||
$this->setLevel(ConfigQuery::read(self::VAR_LEVEL, self::DEFAULT_LEVEL));
|
||||
|
||||
$this->dir_destinations = array(
|
||||
__DIR__.'/Destination'
|
||||
//, __DIR__.'/../client/tlog/destinations'
|
||||
);
|
||||
|
||||
$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, 'writeOnExit'));
|
||||
}
|
||||
|
||||
// Configuration
|
||||
// -------------
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $destinations
|
||||
*/
|
||||
public function setDestinations($destinations)
|
||||
{
|
||||
if (! empty($destinations)) {
|
||||
|
||||
$this->destinations = array();
|
||||
|
||||
$classes_destinations = explode(';', $destinations);
|
||||
$this->loadDestinations($this->destinations, $classes_destinations);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* change the debug level. Use Tlog constant : \Thelia\Log\Tlog::DEBUG set level to Debug
|
||||
*
|
||||
* @param int $level
|
||||
*/
|
||||
public function setLevel($level)
|
||||
{
|
||||
$this->level = $level;
|
||||
}
|
||||
|
||||
public function setPrefix($prefixe)
|
||||
{
|
||||
$this->prefixe = $prefixe;
|
||||
}
|
||||
|
||||
public function setFiles($files)
|
||||
{
|
||||
$this->files = explode(";", $files);
|
||||
|
||||
$this->all_files = in_array('*', $this->files);
|
||||
}
|
||||
|
||||
public function setIp($ips)
|
||||
{
|
||||
// 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 setShowRedirect($bool)
|
||||
{
|
||||
$this->show_redirect = $bool;
|
||||
}
|
||||
|
||||
// Configuration d'une destination
|
||||
public function setConfig($destination, $param, $valeur)
|
||||
{
|
||||
if (isset($this->destinations[$destination])) {
|
||||
$this->destinations[$destination]->setConfig($param, $valeur);
|
||||
}
|
||||
}
|
||||
|
||||
// Configuration d'une destination
|
||||
public function getConfig($destination, $param)
|
||||
{
|
||||
if (isset($this->destinations[$destination])) {
|
||||
return $this->destinations[$destination]->getConfig($param);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Methodes d'accès aux traces
|
||||
// ---------------------------
|
||||
|
||||
/**
|
||||
* Detailed debug information.
|
||||
*
|
||||
* @param string $message
|
||||
* @param array $context
|
||||
* @return null
|
||||
*/
|
||||
public function debug($message, array $context = array())
|
||||
{
|
||||
$this->log(self::DEBUG, $message, $context);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Alias of debug method. With this method you can put all parameter you want
|
||||
*
|
||||
* ex : Tlog::getInstance()->addDebug($arg1, $arg2, $arg3);
|
||||
*
|
||||
*/
|
||||
public function addDebug()
|
||||
{
|
||||
$args = func_get_args();
|
||||
|
||||
foreach ($args as $arg) {
|
||||
$this->log(self::DEBUG, $arg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Interesting events.
|
||||
*
|
||||
* Example: User logs in, SQL logs.
|
||||
*
|
||||
* @param string $message
|
||||
* @param array $context
|
||||
* @return null
|
||||
*/
|
||||
public function info($message, array $context = array())
|
||||
{
|
||||
$this->log(self::INFO, $message, $context);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Alias of info method. With this method you can put all parameter you want
|
||||
*
|
||||
* ex : Tlog::getInstance()->addInfo($arg1, $arg2, $arg3);
|
||||
*
|
||||
*/
|
||||
public function addInfo()
|
||||
{
|
||||
$args = func_get_args();
|
||||
|
||||
foreach ($args as $arg) {
|
||||
$this->log(self::INFO, $arg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Normal but significant events.
|
||||
*
|
||||
* @param string $message
|
||||
* @param array $context
|
||||
* @return null
|
||||
*/
|
||||
public function notice($message, array $context = array())
|
||||
{
|
||||
$this->log(self::NOTICE, $message, $context);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Alias of notice method. With this method you can put all parameter you want
|
||||
*
|
||||
* ex : Tlog::getInstance()->addNotice($arg1, $arg2, $arg3);
|
||||
*
|
||||
*/
|
||||
public function addNotice()
|
||||
{
|
||||
$args = func_get_args();
|
||||
|
||||
foreach ($args as $arg) {
|
||||
$this->log(self::NOTICE, $arg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Exceptional occurrences that are not errors.
|
||||
*
|
||||
* Example: Use of deprecated APIs, poor use of an API, undesirable things
|
||||
* that are not necessarily wrong.
|
||||
*
|
||||
* @param string $message
|
||||
* @param array $context
|
||||
* @return null
|
||||
*/
|
||||
public function warning($message, array $context = array())
|
||||
{
|
||||
$this->log(self::WARNING, $message, $context);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Alias of warning method. With this method you can put all parameter you want
|
||||
*
|
||||
* ex : Tlog::getInstance()->addWarning($arg1, $arg2, $arg3);
|
||||
*
|
||||
*/
|
||||
public function addWarning()
|
||||
{
|
||||
$args = func_get_args();
|
||||
|
||||
foreach ($args as $arg) {
|
||||
$this->log(self::WARNING, $arg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Runtime errors that do not require immediate action but should typically
|
||||
* be logged and monitored.
|
||||
*
|
||||
* @param string $message
|
||||
* @param array $context
|
||||
* @return null
|
||||
*/
|
||||
public function error($message, array $context = array())
|
||||
{
|
||||
$this->log(self::ERROR, $message, $context);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Alias of error method. With this method you can put all parameter you want
|
||||
*
|
||||
* ex : Tlog::getInstance()->addError($arg1, $arg2, $arg3);
|
||||
*
|
||||
*/
|
||||
public function addError()
|
||||
{
|
||||
$args = func_get_args();
|
||||
|
||||
foreach ($args as $arg) {
|
||||
$this->log(self::ERROR, $arg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @see error()
|
||||
*/
|
||||
public function err($message, array $context = array())
|
||||
{
|
||||
$this->error($message, $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Critical conditions.
|
||||
*
|
||||
* Example: Application component unavailable, unexpected exception.
|
||||
*
|
||||
* @param string $message
|
||||
* @param array $context
|
||||
* @return null
|
||||
*/
|
||||
public function critical($message, array $context = array())
|
||||
{
|
||||
$this->log(self::CRITICAL, $message, $context);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Alias of critical method. With this method you can put all parameter you want
|
||||
*
|
||||
* ex : Tlog::getInstance()->addCritical($arg1, $arg2, $arg3);
|
||||
*
|
||||
*/
|
||||
public function addCritical()
|
||||
{
|
||||
$args = func_get_args();
|
||||
|
||||
foreach ($args as $arg) {
|
||||
$this->log(self::CRITICAL, $arg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @see critical()
|
||||
*/
|
||||
public function crit($message, array $context = array())
|
||||
{
|
||||
$this->critical($message, $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Action must be taken immediately.
|
||||
*
|
||||
* Example: Entire website down, database unavailable, etc. This should
|
||||
* trigger the SMS alerts and wake you up.
|
||||
*
|
||||
* @param string $message
|
||||
* @param array $context
|
||||
* @return null
|
||||
*/
|
||||
public function alert($message, array $context = array())
|
||||
{
|
||||
$this->log(self::ALERT, $message, $context);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Alias of alert method. With this method you can put all parameter you want
|
||||
*
|
||||
* ex : Tlog::getInstance()->addAlert($arg1, $arg2, $arg3);
|
||||
*
|
||||
*/
|
||||
public function addAlert()
|
||||
{
|
||||
$args = func_get_args();
|
||||
|
||||
foreach ($args as $arg) {
|
||||
$this->log(self::ALERT, $arg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* System is unusable.
|
||||
*
|
||||
* @param string $message
|
||||
* @param array $context
|
||||
* @return null
|
||||
*/
|
||||
public function emergency($message, array $context = array())
|
||||
{
|
||||
$this->log(self::EMERGENCY, $message, $context);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Alias of emergency method. With this method you can put all parameter you want
|
||||
*
|
||||
* ex : Tlog::getInstance()->addEmergency($arg1, $arg2, $arg3);
|
||||
*
|
||||
*/
|
||||
public function addEmergency()
|
||||
{
|
||||
$args = func_get_args();
|
||||
|
||||
foreach ($args as $arg) {
|
||||
$this->log(self::EMERGENCY, $arg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs with an arbitrary level.
|
||||
*
|
||||
* @param mixed $level
|
||||
* @param string $message
|
||||
* @param array $context
|
||||
* @return null
|
||||
*/
|
||||
public function log($level, $message, array $context = array()) {
|
||||
if($this->level > $level || array_key_exists($level, $this->levels) === false)
|
||||
return;
|
||||
|
||||
$this->out($this->levels[$level], $message, $context);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Mode back office
|
||||
public static function SetBackOfficeMode($booleen)
|
||||
{
|
||||
foreach (Tlog::getInstance()->destinations as $dest) {
|
||||
$dest->SetBackOfficeMode($booleen);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* final end method. Write log for each destination handler
|
||||
*
|
||||
* @param string $res
|
||||
* @return void
|
||||
*/
|
||||
public function write(&$res)
|
||||
{
|
||||
self::$done = true;
|
||||
|
||||
// Muet ? On ne fait rien
|
||||
if ($this->level == self::MUET) return;
|
||||
|
||||
foreach ($this->destinations as $dest) {
|
||||
$dest->write($res);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see write()
|
||||
*/
|
||||
public function writeOnExit()
|
||||
{
|
||||
// Si les infos de debug n'ont pas été ecrites, le faire maintenant
|
||||
if (self::$done === false) {
|
||||
|
||||
$res = "";
|
||||
|
||||
$this->write($res);
|
||||
|
||||
echo $res;
|
||||
}
|
||||
}
|
||||
|
||||
public function showRedirect($url)
|
||||
{
|
||||
if ($this->level != self::MUET && $this->show_redirect) {
|
||||
echo "
|
||||
<html>
|
||||
<head><title>Redirection...</title></head>
|
||||
<body>
|
||||
<a href=\"$url\">Redirection vers $url</a>
|
||||
</body>
|
||||
</html>
|
||||
";
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* check if level is activated and control if current file is activated
|
||||
*
|
||||
* @param int $level
|
||||
* @return boolean
|
||||
*/
|
||||
public function isActivated($level)
|
||||
{
|
||||
if ($this->level <= $level) {
|
||||
|
||||
$origin = $this->findOrigin();
|
||||
|
||||
$file = basename($origin['file']);
|
||||
|
||||
if ($this->isActivedFile($file)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* check if $file is in authorized files
|
||||
*
|
||||
* @param string $file
|
||||
* @return boolean
|
||||
*/
|
||||
public function isActivedFile($file)
|
||||
{
|
||||
return ($this->all_files || in_array($file, $this->files)) && ! in_array("!$file", $this->files);
|
||||
}
|
||||
|
||||
/* -- Methodes privees ---------------------------------------- */
|
||||
|
||||
|
||||
private function findOrigin()
|
||||
{
|
||||
$origine = array();
|
||||
|
||||
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'])) {
|
||||
// we are sometimes in functions = no class available: avoid php warning here
|
||||
$className = $hop['class'];
|
||||
|
||||
if (! empty($className) and ($className == ltrim(__CLASS__,'\\') or strtolower(get_parent_class($className)) == ltrim(__CLASS__,'\\'))) {
|
||||
$origine['line'] = $hop['line'];
|
||||
$origine['file'] = $hop['file'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
$prevHop = $hop;
|
||||
$hop = array_pop($trace);
|
||||
}
|
||||
|
||||
$origine['class'] = isset($prevHop['class']) ? $prevHop['class'] : 'main';
|
||||
|
||||
if(isset($prevHop['function']) and
|
||||
$prevHop['function'] !== 'include' and
|
||||
$prevHop['function'] !== 'include_once' and
|
||||
$prevHop['function'] !== 'require' and
|
||||
$prevHop['function'] !== 'require_once') {
|
||||
|
||||
$origine['function'] = $prevHop['function'];
|
||||
} else {
|
||||
$origine['function'] = 'main';
|
||||
}
|
||||
}
|
||||
|
||||
return $origine;
|
||||
}
|
||||
|
||||
protected function interpolate($message, array $context = array())
|
||||
{
|
||||
// build a replacement array with braces around the context keys
|
||||
$replace = array();
|
||||
foreach ($context as $key => $val) {
|
||||
$replace['{' . $key . '}'] = $val;
|
||||
}
|
||||
|
||||
// interpolate replacement values into the message and return
|
||||
return strtr($message, $replace);
|
||||
}
|
||||
|
||||
private function out($level, $message, array $context = array())
|
||||
{
|
||||
$text = '';
|
||||
|
||||
/*if (is_array($message)) {
|
||||
foreach ($message as $arg) {
|
||||
$text .= is_scalar($arg) ? $arg : print_r($arg, true);
|
||||
}
|
||||
} else */ if (is_scalar($message) === false) {
|
||||
$text = print_r($message, true);
|
||||
} else {
|
||||
$text = $message;
|
||||
}
|
||||
|
||||
$text = $this->interpolate($text, $context);
|
||||
|
||||
$origine = $this->findOrigin();
|
||||
|
||||
$file = basename($origine['file']);
|
||||
|
||||
if ($this->isActivedFile($file)) {
|
||||
|
||||
$function = $origine['function'];
|
||||
$line = $origine['line'];
|
||||
|
||||
$prefixe = str_replace(
|
||||
array("#NUM", "#NIVEAU", "#FICHIER", "#FONCTION", "#LIGNE", "#DATE", "#HEURE"),
|
||||
array(1+$this->linecount, $level, $file, $function, $line, date("Y-m-d"), date("G:i:s")),
|
||||
$this->prefixe
|
||||
);
|
||||
|
||||
$trace = $prefixe . $text;
|
||||
|
||||
foreach ($this->destinations as $dest) {
|
||||
$dest->add($trace);
|
||||
}
|
||||
|
||||
$this->linecount++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @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)) {
|
||||
$class = new $active();
|
||||
|
||||
if (!$class instanceof AbstractTlogDestination) {
|
||||
throw new \UnexpectedValueException($active." must extends Thelia\Tlog\AbstractTlogDestination");
|
||||
}
|
||||
|
||||
$destinations[$active] = $class;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
70
documentation/api/files/Log/TlogDestinationConfig.php.txt
Normal file
70
documentation/api/files/Log/TlogDestinationConfig.php.txt
Normal file
@@ -0,0 +1,70 @@
|
||||
<?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;
|
||||
use Thelia\Model\ConfigDesc;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
|
||||
class TlogDestinationConfig
|
||||
{
|
||||
|
||||
const TYPE_TEXTAREA = 1;
|
||||
const TYPE_TEXTFIELD = 2;
|
||||
|
||||
public $name;
|
||||
public $title;
|
||||
public $label;
|
||||
public $default;
|
||||
public $type;
|
||||
public $value;
|
||||
|
||||
public function __construct($name, $title, $label, $default, $type)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->title = $title;
|
||||
$this->label = $label;
|
||||
$this->default = $default;
|
||||
$this->type = $type;
|
||||
|
||||
$this->load();
|
||||
}
|
||||
|
||||
|
||||
public function load()
|
||||
{
|
||||
if (null === $config = ConfigQuery::create()->findOneByName($this->name))
|
||||
{
|
||||
$config = new Config();
|
||||
$config->setName($this->name);
|
||||
$config->setValue($this->default);
|
||||
$config->setHidden(1);
|
||||
$config->setSecured(1);
|
||||
$config->save();
|
||||
}
|
||||
|
||||
$this->value = $config->getValue();
|
||||
}
|
||||
}
|
||||
|
||||
16
documentation/api/files/Log/TlogInterface.php.txt
Normal file
16
documentation/api/files/Log/TlogInterface.php.txt
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
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