Rajout du dossier core + MAJ .gitignore
This commit is contained in:
99
core/lib/Thelia/Log/AbstractTlogDestination.php
Normal file
99
core/lib/Thelia/Log/AbstractTlogDestination.php
Normal file
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Log;
|
||||
|
||||
abstract class AbstractTlogDestination
|
||||
{
|
||||
//Tableau de TlogDestinationConfig paramétrant la destination
|
||||
protected $configs = array();
|
||||
|
||||
//Tableau des lignes de logs stockés avant utilisation par ecrire()
|
||||
protected $logs = array();
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
// 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, $apply_changes = true)
|
||||
{
|
||||
foreach ($this->configs as $config) {
|
||||
if ($config->getName() == $name) {
|
||||
$config->setValue($value);
|
||||
|
||||
// Appliquer les changements
|
||||
if ($apply_changes) {
|
||||
$this->configure();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//Récupère la valeur affectée à une configuration de la destination
|
||||
public function getConfig($name, $default = false)
|
||||
{
|
||||
foreach ($this->configs as $config) {
|
||||
if ($config->getName() == $name) {
|
||||
return $config->getValue();
|
||||
}
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
public function getConfigs()
|
||||
{
|
||||
return $this->configs;
|
||||
}
|
||||
|
||||
//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);
|
||||
}
|
||||
}
|
||||
|
||||
// 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();
|
||||
}
|
||||
133
core/lib/Thelia/Log/Destination/TlogDestinationFile.php
Normal file
133
core/lib/Thelia/Log/Destination/TlogDestinationFile.php
Normal file
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Log\Destination;
|
||||
|
||||
use Thelia\Log\AbstractTlogDestination;
|
||||
use Thelia\Log\TlogDestinationConfig;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
|
||||
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 = "log" . DS . self::TLOG_DEFAULT_NAME;
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
protected function getFilePath()
|
||||
{
|
||||
$filePath = $this->getConfig(self::VAR_PATH_FILE);
|
||||
|
||||
if (preg_match('/^[a-z]:\\\|^\//i', $filePath) === 0) {
|
||||
$filePath = THELIA_ROOT . $filePath;
|
||||
}
|
||||
|
||||
return $filePath;
|
||||
}
|
||||
|
||||
protected function getOpenMode()
|
||||
{
|
||||
return strtolower($this->getConfig(self::VAR_MODE, self::VALEUR_MODE_DEFAULT)) == 'a' ? 'a' : 'w';
|
||||
}
|
||||
|
||||
public function configure()
|
||||
{
|
||||
$filePath = $this->getFilePath();
|
||||
$mode = $this->getOpenMode();
|
||||
|
||||
if (!empty($filePath)) {
|
||||
$this->resolvePath($filePath, $mode);
|
||||
}
|
||||
}
|
||||
|
||||
protected function resolvePath($filePath, $mode)
|
||||
{
|
||||
if (! empty($filePath)) {
|
||||
if (! is_file($filePath)) {
|
||||
$dir = dirname($filePath);
|
||||
if (! is_dir($dir)) {
|
||||
mkdir($dir, 0777, true);
|
||||
}
|
||||
|
||||
touch($filePath);
|
||||
chmod($filePath, 0666);
|
||||
}
|
||||
|
||||
if ($this->fh) {
|
||||
@fclose($this->fh);
|
||||
}
|
||||
|
||||
$this->fh = fopen($filePath, $mode);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return Translator::getInstance()->trans('Text File');
|
||||
}
|
||||
|
||||
public function getDescription()
|
||||
{
|
||||
return Translator::getInstance()->trans('Store logs into text file');
|
||||
}
|
||||
|
||||
public function getConfigs()
|
||||
{
|
||||
return array(
|
||||
new TlogDestinationConfig(
|
||||
self::VAR_PATH_FILE,
|
||||
'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,
|
||||
'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
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
66
core/lib/Thelia/Log/Destination/TlogDestinationHtml.php
Normal file
66
core/lib/Thelia/Log/Destination/TlogDestinationHtml.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Log\Destination;
|
||||
|
||||
use Thelia\Log\AbstractTlogDestination;
|
||||
use Thelia\Log\TlogDestinationConfig;
|
||||
|
||||
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 "Direct HTML display";
|
||||
}
|
||||
|
||||
public function getDescription()
|
||||
{
|
||||
return "Display logs in HTML format, on top of generated pages.";
|
||||
}
|
||||
|
||||
public function getConfigs()
|
||||
{
|
||||
return array(
|
||||
new TlogDestinationConfig(
|
||||
self::VAR_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
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
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,43 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
38
core/lib/Thelia/Log/Destination/TlogDestinationNull.php
Normal file
38
core/lib/Thelia/Log/Destination/TlogDestinationNull.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Log\Destination;
|
||||
|
||||
use Thelia\Log\AbstractTlogDestination;
|
||||
|
||||
class TlogDestinationNull extends AbstractTlogDestination
|
||||
{
|
||||
public function getTitle()
|
||||
{
|
||||
return "Black hole";
|
||||
}
|
||||
|
||||
public function getDescription()
|
||||
{
|
||||
return "This destinations consumes the logs but don't display them";
|
||||
}
|
||||
|
||||
public function add($string)
|
||||
{
|
||||
// Rien
|
||||
}
|
||||
|
||||
public function write(&$res)
|
||||
{
|
||||
// Rien
|
||||
}
|
||||
}
|
||||
104
core/lib/Thelia/Log/Destination/TlogDestinationPopup.php
Normal file
104
core/lib/Thelia/Log/Destination/TlogDestinationPopup.php
Normal file
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
52
core/lib/Thelia/Log/Destination/TlogDestinationPopup.tpl
Normal file
52
core/lib/Thelia/Log/Destination/TlogDestinationPopup.tpl
Normal 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>
|
||||
119
core/lib/Thelia/Log/Destination/TlogDestinationRotatingFile.php
Normal file
119
core/lib/Thelia/Log/Destination/TlogDestinationRotatingFile.php
Normal file
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Log\Destination;
|
||||
|
||||
use Symfony\Component\Finder\Finder;
|
||||
use Thelia\Log\TlogDestinationConfig;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
|
||||
class TlogDestinationRotatingFile extends TlogDestinationFile
|
||||
{
|
||||
// Nom des variables de configuration
|
||||
// ----------------------------------
|
||||
|
||||
const VAR_MAX_FILE_SIZE_KB = "tlog_destinationfile_max_file_size";
|
||||
const VAR_MAX_FILE_COUNT = "tlog_destinationfile_max_file_count";
|
||||
|
||||
const MAX_FILE_SIZE_KB_DEFAULT = 1024; // 1 Mb
|
||||
const MAX_FILE_COUNT_DEFAULT = 10;
|
||||
|
||||
public function __construct($maxFileSize = self::MAX_FILE_SIZE_KB_DEFAULT)
|
||||
{
|
||||
$this->path_defaut = "log" . DS . self::TLOG_DEFAULT_NAME;
|
||||
|
||||
$this->setConfig(self::VAR_MAX_FILE_SIZE_KB, $maxFileSize, false);
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function configure()
|
||||
{
|
||||
parent::configure();
|
||||
|
||||
$filePath = $this->getFilePath();
|
||||
$mode = $this->getOpenMode();
|
||||
|
||||
if ($this->fh) {
|
||||
@fclose($this->fh);
|
||||
}
|
||||
|
||||
if (filesize($filePath) > 1024 * $this->getConfig(self::VAR_MAX_FILE_SIZE_KB, self::MAX_FILE_SIZE_KB_DEFAULT)) {
|
||||
$backupFile = $filePath . '.' . strftime('%Y-%m-%d_%H-%M-%S');
|
||||
|
||||
@rename($filePath, $backupFile);
|
||||
|
||||
@touch($filePath);
|
||||
@chmod($filePath, 0666);
|
||||
|
||||
// Keep the number of files below VAR_MAX_FILE_COUNT
|
||||
$maxCount = $this->getConfig(self::VAR_MAX_FILE_COUNT, self::MAX_FILE_COUNT_DEFAULT);
|
||||
|
||||
$finder = new Finder();
|
||||
|
||||
$files = $finder
|
||||
->in(dirname($filePath))
|
||||
->files()
|
||||
->name(basename($filePath).'.*')
|
||||
->sortByModifiedTime();
|
||||
|
||||
$deleteCount = 1 + $files->count() - $maxCount;
|
||||
|
||||
if ($deleteCount > 0) {
|
||||
foreach ($files as $file) {
|
||||
@unlink($file);
|
||||
|
||||
if (--$deleteCount <= 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->fh = fopen($filePath, $mode);
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return Translator::getInstance()->trans('Rotated Text File');
|
||||
}
|
||||
|
||||
public function getDescription()
|
||||
{
|
||||
return Translator::getInstance()->trans('Store logs into text file, up to a certian size, then a new file is created');
|
||||
}
|
||||
|
||||
public function getConfigs()
|
||||
{
|
||||
$arr = parent::getConfigs();
|
||||
|
||||
$arr[] =
|
||||
new TlogDestinationConfig(
|
||||
self::VAR_MAX_FILE_SIZE_KB,
|
||||
'Maximum log file size, in Kb',
|
||||
'When this size if exeeded, a backup copy of the file is made, and a new log file is opened. As the file size check is performed only at the beginning of a request, the file size may be bigger thant this limit. Note: 1 Mb = 1024 Kb',
|
||||
self::MAX_FILE_SIZE_KB_DEFAULT,
|
||||
TlogDestinationConfig::TYPE_TEXTFIELD
|
||||
);
|
||||
|
||||
$arr[] =
|
||||
new TlogDestinationConfig(
|
||||
self::VAR_MAX_FILE_COUNT,
|
||||
'Maximum number of files to keep',
|
||||
'When this number if exeeded, the oldest files are deleted.',
|
||||
self::MAX_FILE_COUNT_DEFAULT,
|
||||
TlogDestinationConfig::TYPE_TEXTFIELD
|
||||
);
|
||||
|
||||
return $arr;
|
||||
}
|
||||
}
|
||||
43
core/lib/Thelia/Log/Destination/TlogDestinationText.php
Normal file
43
core/lib/Thelia/Log/Destination/TlogDestinationText.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Log\Destination;
|
||||
|
||||
use Thelia\Log\AbstractTlogDestination;
|
||||
|
||||
class TlogDestinationText extends AbstractTlogDestination
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return "Direct text display";
|
||||
}
|
||||
|
||||
public function getDescription()
|
||||
{
|
||||
return "Display logs in raw text format, on top of generated pages.";
|
||||
}
|
||||
|
||||
public function add($texte)
|
||||
{
|
||||
echo trim($texte)."\n";
|
||||
}
|
||||
|
||||
public function write(&$res)
|
||||
{
|
||||
// Rien
|
||||
}
|
||||
}
|
||||
722
core/lib/Thelia/Log/Tlog.php
Normal file
722
core/lib/Thelia/Log/Tlog.php
Normal file
@@ -0,0 +1,722 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
namespace Thelia\Log;
|
||||
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
|
||||
/**
|
||||
*
|
||||
* Thelia Logger
|
||||
*
|
||||
* Allow to define different level and output.
|
||||
*
|
||||
* @author Franck Allimant <franck@cqfdev.fr>
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
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::ERROR;
|
||||
const DEFAUT_DESTINATIONS = "Thelia\Log\Destination\TlogDestinationRotatingFile";
|
||||
const DEFAUT_PREFIXE = "#INDEX: #LEVEL [#FILE:#FUNCTION()] {#LINE} #DATE #HOUR: ";
|
||||
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 $prefix = "";
|
||||
protected $files = array();
|
||||
protected $all_files = false;
|
||||
protected $show_redirect = false;
|
||||
|
||||
private $linecount = 0;
|
||||
|
||||
protected $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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new Tlog instance, that could be configured without interfering with the "main" instance
|
||||
*
|
||||
* @return Tlog a new Tlog instance.
|
||||
*/
|
||||
public static function getNewInstance()
|
||||
{
|
||||
$instance = new Tlog();
|
||||
|
||||
$instance->init();
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* initialize default configuration
|
||||
*/
|
||||
protected function init()
|
||||
{
|
||||
$this->setLevel(ConfigQuery::read(self::VAR_LEVEL, self::DEFAULT_LEVEL));
|
||||
|
||||
$this->dir_destinations = array(
|
||||
__DIR__.DS.'Destination',
|
||||
THELIA_LOCAL_DIR.'tlog'.DS.'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);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* @param int $level
|
||||
*/
|
||||
public function setLevel($level)
|
||||
{
|
||||
$this->level = $level;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setPrefix($prefix)
|
||||
{
|
||||
$this->prefix = $prefix;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setFiles($files)
|
||||
{
|
||||
$this->files = explode(";", $files);
|
||||
|
||||
$this->all_files = in_array('*', $this->files);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setShowRedirect($bool)
|
||||
{
|
||||
$this->show_redirect = $bool;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
// Configuration d'une destination
|
||||
public function setConfig($destination, $param, $valeur)
|
||||
{
|
||||
if (isset($this->destinations[$destination])) {
|
||||
$this->destinations[$destination]->setConfig($param, $valeur);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* final end method. Write log for each destination handler
|
||||
*
|
||||
* @param string $res
|
||||
* @return void
|
||||
*/
|
||||
public function write(&$res)
|
||||
{
|
||||
$this->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 ($this->done === false) {
|
||||
$res = "";
|
||||
|
||||
$this->write($res);
|
||||
|
||||
echo $res;
|
||||
}
|
||||
}
|
||||
|
||||
public function showRedirect($url)
|
||||
{
|
||||
if ($this->level != self::MUET && $this->show_redirect) {
|
||||
echo "
|
||||
<html>
|
||||
<head><title>".Translator::getInstance()->trans('Redirecting ...')."</title></head>
|
||||
<body>
|
||||
<a href=\"$url\">".Translator::getInstance()->trans('Redirecting to %url', array('%url' => $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()
|
||||
{
|
||||
$origin = 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) && ($className == ltrim(__CLASS__, '\\') || strtolower(get_parent_class($className)) == ltrim(__CLASS__, '\\'))) {
|
||||
$origin['line'] = $hop['line'];
|
||||
$origin['file'] = $hop['file'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
$prevHop = $hop;
|
||||
$hop = array_pop($trace);
|
||||
}
|
||||
|
||||
$origin['class'] = isset($prevHop['class']) ? $prevHop['class'] : 'main';
|
||||
|
||||
if (isset($prevHop['function']) &&
|
||||
$prevHop['function'] !== 'include' &&
|
||||
$prevHop['function'] !== 'include_once' &&
|
||||
$prevHop['function'] !== 'require' &&
|
||||
$prevHop['function'] !== 'require_once') {
|
||||
$origin['function'] = $prevHop['function'];
|
||||
} else {
|
||||
$origin['function'] = 'main';
|
||||
}
|
||||
}
|
||||
|
||||
return $origin;
|
||||
}
|
||||
|
||||
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 ($message instanceof \Exception) {
|
||||
$text = $message->getMessage()."\n".$message->getTraceAsString();
|
||||
} elseif (is_scalar($message) === false) {
|
||||
$text = print_r($message, 1);
|
||||
} else {
|
||||
$text = $message;
|
||||
}
|
||||
|
||||
$text = $this->interpolate($text, $context);
|
||||
|
||||
$origin = $this->findOrigin();
|
||||
|
||||
$file = basename($origin['file']);
|
||||
|
||||
if ($this->isActivedFile($file)) {
|
||||
$function = $origin['function'];
|
||||
$line = $origin['line'];
|
||||
|
||||
$prefix = str_replace(
|
||||
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->prefix
|
||||
);
|
||||
|
||||
$trace = $prefix . $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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
98
core/lib/Thelia/Log/TlogDestinationConfig.php
Normal file
98
core/lib/Thelia/Log/TlogDestinationConfig.php
Normal file
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Log;
|
||||
|
||||
use Thelia\Model\ConfigQuery;
|
||||
|
||||
class TlogDestinationConfig
|
||||
{
|
||||
const TYPE_TEXTAREA = 1;
|
||||
const TYPE_TEXTFIELD = 2;
|
||||
|
||||
protected $name;
|
||||
protected $title;
|
||||
protected $label;
|
||||
protected $default;
|
||||
protected $type;
|
||||
protected $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->value = ConfigQuery::read($this->name, $this->default);
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user