Finished log configuration. All loggers are currentrly working

This commit is contained in:
Franck Allimant
2013-11-01 16:15:19 +01:00
parent 1dc6aa52cb
commit 2aefb87db7
58 changed files with 2236 additions and 1438 deletions

View File

@@ -31,9 +31,6 @@ abstract class AbstractTlogDestination
//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();
@@ -50,8 +47,8 @@ abstract class AbstractTlogDestination
public function setConfig($name, $value)
{
foreach ($this->_configs as $config) {
if ($config->name == $name) {
$config->value = $value;
if ($config->getName() == $name) {
$config->setValue($value);
// Appliquer les changements
$this->configure();
@@ -66,8 +63,8 @@ abstract class AbstractTlogDestination
public function getConfig($name)
{
foreach ($this->_configs as $config) {
if ($config->name == $name) {
return $config->value;
if ($config->getName() == $name) {
return $config->getValue();
}
}
@@ -79,26 +76,19 @@ abstract class AbstractTlogDestination
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)
protected function insertAfterBody(&$res, $logdata)
{
$match = array();
$match = array();
if (preg_match("/(<body[^>]*>)/i", $res, $match)) {
$res = str_replace($match[0], $match[0] . "\n" . $logdata, $res);
} else {
$res = $logdata . $res;
}
if (preg_match("/(<body[^>]*>)/i", $res, $match)) {
$res = str_replace($match[0], $match[0] . "\n" . $logdata, $res);
}
}
// Demande à la destination de se configurer pour être prête
@@ -106,7 +96,7 @@ abstract class AbstractTlogDestination
// que seul le paramètre de configuration indiqué a été modifié.
protected function configure()
{
// Cette methode doit etre surchargée si nécessaire.
// Cette methode doit etre surchargée si nécessaire.
}
//Lance l'écriture de tous les logs par la destination

View File

@@ -25,6 +25,7 @@ namespace Thelia\Log\Destination;
use Thelia\Log\AbstractTlogDestination;
use Thelia\Log\TlogDestinationConfig;
use Thelia\Core\Translation\Translator;
class TlogDestinationFile extends AbstractTlogDestination
{
@@ -41,7 +42,7 @@ class TlogDestinationFile extends AbstractTlogDestination
public function __construct()
{
$this->path_defaut = THELIA_ROOT . "log/" . self::TLOG_DEFAULT_NAME;
$this->path_defaut = THELIA_ROOT . "log" . DS . self::TLOG_DEFAULT_NAME;
parent::__construct();
}
@@ -69,12 +70,12 @@ class TlogDestinationFile extends AbstractTlogDestination
public function getTitle()
{
return "Text File";
return Translator::getInstance()->trans('Text File');
}
public function getDescription()
{
return "Store logs into text file";
return Translator::getInstance()->trans('Store logs into text file');
}
public function getConfigs()
@@ -82,15 +83,15 @@ class TlogDestinationFile extends AbstractTlogDestination
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()),
'Absolute file path',
'You should enter an abolute file path. The base directory of your Thelia installation is '.THELIA_ROOT,
$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 !",
'File opening mode (A or E)',
'Enter E to empty this file for each request, or A to always append logs. Consider resetting the file from time to time',
self::VALEUR_MODE_DEFAULT,
TlogDestinationConfig::TYPE_TEXTFIELD
)

View File

@@ -24,6 +24,7 @@
namespace Thelia\Log\Destination;
use Thelia\Log\AbstractTlogDestination;
use Thelia\Log\TlogDestinationConfig;
class TlogDestinationHtml extends AbstractTlogDestination
{
@@ -46,12 +47,12 @@ class TlogDestinationHtml extends AbstractTlogDestination
public function getTitle()
{
return "Affichage direct dans la page, en HTML";
return "Direct HTML display";
}
public function getDescription()
{
return "Permet d'afficher les logs directement dans la page resultat, avec une mise en forme HTML.";
return "Display logs in HTML format, on top of generated pages.";
}
public function getConfigs()
@@ -59,8 +60,8 @@ class TlogDestinationHtml extends AbstractTlogDestination
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.",
"CSS of each log line",
"You may also leave this field empty, and define a \"tlog-trace\" style in your CSS.",
self::VALEUR_STYLE_DEFAUT,
TlogDestinationConfig::TYPE_TEXTAREA
)
@@ -71,6 +72,6 @@ class TlogDestinationHtml extends AbstractTlogDestination
{
$block = sprintf('<pre class="tlog-trace" style="%s">%s</pre>', $this->style, htmlspecialchars(implode("\n", $this->_logs)));
$this->InsertAfterBody($res, $block);
$this->insertAfterBody($res, $block);
}
}

View File

@@ -0,0 +1,51 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : thelia@openstudio.fr */
/* web : http://www.openstudio.fr */
/* */
/* 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 TlogDestinationJavascriptConsole extends AbstractTlogDestination {
public function getTitle() {
return "Browser's Javascript console";
}
public function getDescription() {
return "The Thelia logs are displayed in your browser's Javascript console.";
}
public function write(&$res) {
$content = '<script>try {'."\n";
foreach($this->_logs as $line) {
$content .= "console.log('".str_replace("'", "\\'", str_replace(array("\r\n", "\r", "\n"), '\\n', $line))."');\n";
}
$content .= '} catch(ex) { alert("Les logs Thelia ne peuvent être affichés dans la console javascript:" + ex); }</script>'."\n";
if (preg_match("|</body>|i", $res))
$res = preg_replace("|</body>|i", "$content</html>", $res);
}
}

View File

@@ -29,12 +29,12 @@ class TlogDestinationNull extends AbstractTlogDestination
{
public function getTitle()
{
return "Trou noir";
return "Black hole";
}
public function getDescription()
{
return "Cette destination ne provoque aucune sortie";
return "This destinations consumes the logs but don't display them";
}
public function add($string)

View File

@@ -0,0 +1,111 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : thelia@openstudio.fr */
/* web : http://www.openstudio.fr */
/* */
/* 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 TlogDestinationPopup extends AbstractTlogDestination {
// Nom des variables de configuration
// ----------------------------------
const VAR_POPUP_WIDTH = "tlog_destinationpopup_width";
const VALEUR_POPUP_WIDTH_DEFAUT = "600";
const VAR_POPUP_HEIGHT = "tlog_destinationpopup_height";
const VALEUR_POPUP_HEIGHT_DEFAUT = "600";
const VAR_POPUP_TPL = "tlog_destinationpopup_template";
// Ce fichier doit se trouver dans le même répertoire que TlogDestinationPopup.class.php
const VALEUR_POPUP_TPL_DEFAUT = "TlogDestinationPopup.tpl";
public function getTitle() {
return "Javascript popup window";
}
public function getDescription() {
return "Display logs in a popup window, separate from the main window .";
}
public function getConfigs() {
return array(
new TlogDestinationConfig(
self::VAR_POPUP_TPL,
"Popup windows template",
"Put #LOGTEXT in the template text where you want to display logs..",
file_get_contents(__DIR__.DS. self::VALEUR_POPUP_TPL_DEFAUT),
TlogDestinationConfig::TYPE_TEXTAREA
),
new TlogDestinationConfig(
self::VAR_POPUP_HEIGHT,
"Height of the popup window",
"In pixels",
self::VALEUR_POPUP_HEIGHT_DEFAUT,
TlogDestinationConfig::TYPE_TEXTFIELD
),
new TlogDestinationConfig(
self::VAR_POPUP_WIDTH,
"Width of the popup window",
"In pixels",
self::VALEUR_POPUP_WIDTH_DEFAUT,
TlogDestinationConfig::TYPE_TEXTFIELD
)
);
}
public function write(&$res) {
$content = ""; $count = 1;
foreach($this->_logs as $line) {
$content .= "<div class=\"".($count++ % 2 ? "paire" : "impaire")."\">".htmlspecialchars($line)."</div>";
}
$tpl = $this->getConfig(self::VAR_POPUP_TPL);
$tpl = str_replace('#LOGTEXT', $content, $tpl);
$tpl = str_replace(array("\r\n", "\r", "\n"), '\\n', $tpl);
$wop = sprintf('
<script>
_thelia_console = window.open("","thelia_console","width=%s,height=%s,resizable,scrollbars=yes");
if (_thelia_console == null) {
alert("The log popup window could not be opened. Please disable your popup blocker for this site.");
}
else {
_thelia_console.document.write("%s");
_thelia_console.document.close();
}
</script>',
$this->getConfig(self::VAR_POPUP_WIDTH),
$this->getConfig(self::VAR_POPUP_HEIGHT),
str_replace('"', '\\"', $tpl)
);
if (preg_match("|</body>|i", $res))
$res = preg_replace("|</body>|i", "$wop\n</body>", $res);
else
$res .= $wop;
}
}

View File

@@ -0,0 +1,52 @@
<!--
Default template for TlogDestinationPopup. Insert #LOGTEXT where you want to
write the log text in your template.
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Thelia logs</title>
<style type="text/css">
body, h1, h2, td, th, p {
font-family: "Courier New", courier, fixed;
font-weight: normal;
font-size: 0.9em;
margin: 0;
padding: 0;
}
h1 {
background-color: #868F99;
border-bottom: 2px solid #127AED;
color: #FFFFFF;
font-family: Arial,Helvetica,sans-serif;
font-weight: bold;
line-height: 20px;
padding: 5px;
}
pre {
margin: 0;
}
.paire {
background-color: #EBEDEE;
padding: 5px;
border-bottom: 1px dotted #fff;
}
.impaire {
background-color: #D4DADD;
padding: 5px;
border-bottom: 1px dotted #fff;
}
</style>
</head>
<body>
<h1>Thelia Debug</h1>
<pre>#LOGTEXT</pre>
</body>
</html>

View File

@@ -34,12 +34,12 @@ class TlogDestinationText extends AbstractTlogDestination
public function getTitle()
{
return "Affichage direct dans la page, en texte brut";
return "Direct text display";
}
public function getDescription()
{
return "Permet d'afficher les logs directement dans la page resultat, au format texte brut.";
return "Display logs in raw text format, on top of generated pages.";
}
public function add($texte)

View File

@@ -24,6 +24,7 @@ namespace Thelia\Log;
use Thelia\Model\ConfigQuery;
use Psr\Log\LoggerInterface;
use Thelia\Core\Translation\Translator;
/**
*
@@ -69,7 +70,7 @@ class Tlog Implements LoggerInterface
// 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_PREFIXE = "#INDEX: #LEVEL [#FILE:#FUNCTION()] {#LINE} #DATE #HOUR: ";
const DEFAUT_FILES = "*";
const DEFAUT_IP = "";
const DEFAUT_SHOW_REDIRECT = 0;
@@ -95,7 +96,7 @@ class Tlog Implements LoggerInterface
private $linecount = 0;
protected static $done = false;
protected $done = false;
// directories where are the Destinations Files
public $dir_destinations = array();
@@ -132,8 +133,8 @@ class Tlog Implements LoggerInterface
$this->setLevel(ConfigQuery::read(self::VAR_LEVEL, self::DEFAULT_LEVEL));
$this->dir_destinations = array(
__DIR__.'/Destination'
//, __DIR__.'/../client/tlog/destinations'
__DIR__.DS.'Destination',
THELIA_LOCAL_DIR.'tlog'.DS.'destinations'
);
$this->setPrefix(ConfigQuery::read(self::VAR_PREFIXE, self::DEFAUT_PREFIXE));
@@ -160,10 +161,20 @@ class Tlog Implements LoggerInterface
$this->destinations = array();
$classes_destinations = explode(';', $destinations);
$this->loadDestinations($this->destinations, $classes_destinations);
}
}
/**
* Return the directories where destinations classes should be searched.
*
* @return array of directories
*/
public function getDestinationsDirectories() {
return $this->dir_destinations;
}
/**
*
* change the debug level. Use Tlog constant : \Thelia\Log\Tlog::DEBUG set level to Debug
@@ -489,16 +500,6 @@ class Tlog Implements LoggerInterface
$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
@@ -508,7 +509,7 @@ class Tlog Implements LoggerInterface
*/
public function write(&$res)
{
self::$done = true;
$this->done = true;
// Muet ? On ne fait rien
if ($this->level == self::MUET) return;
@@ -524,7 +525,7 @@ class Tlog Implements LoggerInterface
public function writeOnExit()
{
// Si les infos de debug n'ont pas été ecrites, le faire maintenant
if (self::$done === false) {
if ($this->done === false) {
$res = "";
@@ -539,12 +540,12 @@ class Tlog Implements LoggerInterface
if ($this->level != self::MUET && $this->show_redirect) {
echo "
<html>
<head><title>Redirection...</title></head>
<head><title>".Translator::getInstance()->trans('Redirecting ...')."</title></head>
<body>
<a href=\"$url\">Redirection vers $url</a>
<a href=\"$url\">".Translator::getInstance()->trans('Redirecting to %url', array('%url' => $url))."</a>
</body>
</html>
";
";
return true;
} else {
@@ -670,7 +671,7 @@ class Tlog Implements LoggerInterface
$line = $origine['line'];
$prefixe = str_replace(
array("#NUM", "#NIVEAU", "#FICHIER", "#FONCTION", "#LIGNE", "#DATE", "#HEURE"),
array("#INDEX", "#LEVEL", "#FILE", "#FUNCTION", "#LINE", "#DATE", "#HOUR"),
array(1+$this->linecount, $level, $file, $function, $line, date("Y-m-d"), date("G:i:s")),
$this->prefixe
);

View File

@@ -22,7 +22,6 @@
/*************************************************************************************/
namespace Thelia\Log;
use Thelia\Model\Config;
use Thelia\Model\ConfigQuery;
@@ -32,12 +31,12 @@ class TlogDestinationConfig
const TYPE_TEXTAREA = 1;
const TYPE_TEXTFIELD = 2;
public $name;
public $title;
public $label;
public $default;
public $type;
public $value;
protected $name;
protected $title;
protected $label;
protected $default;
protected $type;
protected $value;
public function __construct($name, $title, $label, $default, $type)
{
@@ -45,22 +44,67 @@ class TlogDestinationConfig
$this->title = $title;
$this->label = $label;
$this->default = $default;
$this->type = $type;
$this->load();
$this->type= $type;
$this->value = ConfigQuery::read($this->name, $this->default);
}
public function load()
public function getName()
{
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();
}
return $this->name;
}
$this->value = $config->getValue();
public function setName($name)
{
$this->name = $name;
}
public function getTitle()
{
return $this->title;
}
public function setTitle($title)
{
$this->title = $title;
}
public function getLabel()
{
return $this->label;
}
public function setLabel($label)
{
$this->label = $label;
}
public function getDefault()
{
return $this->default;
}
public function setDefault($default)
{
$this->default = $default;
}
public function getType()
{
return $this->type;
}
public function setType($type)
{
$this->type = $type;
}
public function getValue()
{
return $this->value;
}
public function setValue($value)
{
$this->value = $value;
}
}