Inital commit
This commit is contained in:
@@ -31,13 +31,19 @@ class TlogDestinationFile extends AbstractTlogDestination
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->path_defaut = THELIA_ROOT . "log" . DS . self::TLOG_DEFAULT_NAME;
|
||||
$this->path_defaut = "log" . DS . self::TLOG_DEFAULT_NAME;
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
protected function getFilePath()
|
||||
{
|
||||
return $this->getConfig(self::VAR_PATH_FILE);
|
||||
$filePath = $this->getConfig(self::VAR_PATH_FILE);
|
||||
|
||||
if (preg_match('/^[a-z]:\\\|^\//i', $filePath) === 0) {
|
||||
$filePath = THELIA_ROOT . $filePath;
|
||||
}
|
||||
|
||||
return $filePath;
|
||||
}
|
||||
|
||||
protected function getOpenMode()
|
||||
@@ -47,34 +53,46 @@ class TlogDestinationFile extends AbstractTlogDestination
|
||||
|
||||
public function configure()
|
||||
{
|
||||
$file_path = $this->getFilePath();
|
||||
$filePath = $this->getFilePath();
|
||||
$mode = $this->getOpenMode();
|
||||
|
||||
if (! empty($file_path)) {
|
||||
if (! is_file($file_path)) {
|
||||
$dir = dirname($file_path);
|
||||
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($file_path);
|
||||
chmod($file_path, 0666);
|
||||
touch($filePath);
|
||||
chmod($filePath, 0666);
|
||||
}
|
||||
|
||||
if ($this->fh) @fclose($this->fh);
|
||||
if ($this->fh) {
|
||||
@fclose($this->fh);
|
||||
}
|
||||
|
||||
$this->fh = fopen($file_path, $mode);
|
||||
$this->fh = fopen($filePath, $mode);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return Translator::getInstance()->trans('Text File');
|
||||
return Translator::getInstance()->trans('Text File');
|
||||
}
|
||||
|
||||
public function getDescription()
|
||||
{
|
||||
return Translator::getInstance()->trans('Store logs into text file');
|
||||
return Translator::getInstance()->trans('Store logs into text file');
|
||||
}
|
||||
|
||||
public function getConfigs()
|
||||
@@ -106,7 +124,9 @@ class TlogDestinationFile extends AbstractTlogDestination
|
||||
|
||||
public function write(&$res)
|
||||
{
|
||||
if ($this->fh) @fclose($this->fh);
|
||||
if ($this->fh) {
|
||||
@fclose($this->fh);
|
||||
}
|
||||
|
||||
$this->fh = false;
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ class TlogDestinationHtml extends AbstractTlogDestination
|
||||
|
||||
public function getDescription()
|
||||
{
|
||||
return "Display logs in HTML format, on top of generated pages.";
|
||||
return "Display logs in HTML format, on top of generated pages.";
|
||||
}
|
||||
|
||||
public function getConfigs()
|
||||
@@ -59,7 +59,7 @@ class TlogDestinationHtml extends AbstractTlogDestination
|
||||
|
||||
public function write(&$res)
|
||||
{
|
||||
$block = sprintf('<pre class="tlog-trace" style="%s">%s</pre>', $this->style, htmlspecialchars(implode("\n", $this->_logs)));
|
||||
$block = sprintf('<pre class="tlog-trace" style="%s">%s</pre>', $this->style, htmlspecialchars(implode("\n", $this->logs)));
|
||||
|
||||
$this->insertAfterBody($res, $block);
|
||||
}
|
||||
|
||||
@@ -30,13 +30,14 @@ class TlogDestinationJavascriptConsole extends AbstractTlogDestination
|
||||
{
|
||||
$content = '<script>try {'."\n";
|
||||
|
||||
foreach ($this->_logs as $line) {
|
||||
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))
|
||||
if (preg_match("|</body>|i", $res)) {
|
||||
$res = preg_replace("|</body>|i", "$content</html>", $res);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,21 +18,21 @@ class TlogDestinationNull extends AbstractTlogDestination
|
||||
{
|
||||
public function getTitle()
|
||||
{
|
||||
return "Black hole";
|
||||
return "Black hole";
|
||||
}
|
||||
|
||||
public function getDescription()
|
||||
{
|
||||
return "This destinations consumes the logs but don't display them";
|
||||
return "This destinations consumes the logs but don't display them";
|
||||
}
|
||||
|
||||
public function add($string)
|
||||
{
|
||||
// Rien
|
||||
// Rien
|
||||
}
|
||||
|
||||
public function write(&$res)
|
||||
{
|
||||
// Rien
|
||||
// Rien
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,34 +43,35 @@ class TlogDestinationPopup extends AbstractTlogDestination
|
||||
{
|
||||
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
|
||||
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
|
||||
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
|
||||
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;
|
||||
$content = "";
|
||||
$count = 1;
|
||||
|
||||
foreach ($this->_logs as $line) {
|
||||
foreach ($this->logs as $line) {
|
||||
$content .= "<div class=\"".($count++ % 2 ? "paire" : "impaire")."\">".htmlspecialchars($line)."</div>";
|
||||
}
|
||||
|
||||
@@ -79,24 +80,25 @@ class TlogDestinationPopup extends AbstractTlogDestination
|
||||
$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)
|
||||
$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))
|
||||
if (preg_match("|</body>|i", $res)) {
|
||||
$res = preg_replace("|</body>|i", "$wop\n</body>", $res);
|
||||
else
|
||||
} else {
|
||||
$res .= $wop;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,52 +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>
|
||||
<!--
|
||||
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>
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
namespace Thelia\Log\Destination;
|
||||
|
||||
use Symfony\Component\Finder\Finder;
|
||||
use Thelia\Log\TlogDestinationConfig;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
|
||||
@@ -21,11 +22,14 @@ class TlogDestinationRotatingFile extends TlogDestinationFile
|
||||
// ----------------------------------
|
||||
|
||||
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 = THELIA_ROOT . "log" . DS . self::TLOG_DEFAULT_NAME;
|
||||
$this->path_defaut = "log" . DS . self::TLOG_DEFAULT_NAME;
|
||||
|
||||
$this->setConfig(self::VAR_MAX_FILE_SIZE_KB, $maxFileSize, false);
|
||||
|
||||
@@ -36,39 +40,56 @@ class TlogDestinationRotatingFile extends TlogDestinationFile
|
||||
{
|
||||
parent::configure();
|
||||
|
||||
$file_path = $this->getFilePath();
|
||||
$filePath = $this->getFilePath();
|
||||
$mode = $this->getOpenMode();
|
||||
|
||||
if ($this->fh) @fclose($this->fh);
|
||||
|
||||
if (filesize($file_path) > 1024 * $this->getConfig(self::VAR_MAX_FILE_SIZE_KB, self::MAX_FILE_SIZE_KB_DEFAULT)) {
|
||||
|
||||
$idx = 1;
|
||||
|
||||
do {
|
||||
$file_path_bk = "$file_path.$idx";
|
||||
|
||||
$idx++;
|
||||
|
||||
} while (file_exists($file_path_bk));
|
||||
|
||||
@rename($file_path, $file_path_bk);
|
||||
|
||||
@touch($file_path);
|
||||
@chmod($file_path, 0666);
|
||||
if ($this->fh) {
|
||||
@fclose($this->fh);
|
||||
}
|
||||
|
||||
$this->fh = fopen($file_path, $mode);
|
||||
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');
|
||||
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');
|
||||
return Translator::getInstance()->trans('Store logs into text file, up to a certian size, then a new file is created');
|
||||
}
|
||||
|
||||
public function getConfigs()
|
||||
@@ -76,13 +97,22 @@ class TlogDestinationRotatingFile extends TlogDestinationFile
|
||||
$arr = parent::getConfigs();
|
||||
|
||||
$arr[] =
|
||||
new TlogDestinationConfig(
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -18,26 +18,26 @@ class TlogDestinationText extends AbstractTlogDestination
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return "Direct text display";
|
||||
return "Direct text display";
|
||||
}
|
||||
|
||||
public function getDescription()
|
||||
{
|
||||
return "Display logs in raw text format, on top of generated pages.";
|
||||
return "Display logs in raw text format, on top of generated pages.";
|
||||
}
|
||||
|
||||
public function add($texte)
|
||||
{
|
||||
echo trim($texte)."\n";
|
||||
echo trim($texte)."\n";
|
||||
}
|
||||
|
||||
public function write(&$res)
|
||||
{
|
||||
// Rien
|
||||
// Rien
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user