BUG-13506 SOLVED La sección ADMIN / Logs, opción Cron, se queda cargando y en consola de navegador se muestra el error 500 internal Server Error.

This commit is contained in:
Roly Gutierrez
2013-11-22 17:05:10 -04:00
parent 7463aa601b
commit 65bb06ff4e
8 changed files with 159 additions and 18 deletions

View File

@@ -85,7 +85,7 @@ class Bootstrap
}
// default configuration
$config = array('debug' => 0, 'debug_sql' => 0, 'debug_time' => 0, 'debug_calendar' => 0, 'wsdl_cache' => 1, 'memory_limit' => "256M", 'time_zone' => 'America/New_York', 'memcached' => 0, 'memcached_server' => '', 'default_skin' => 'neoclassic', 'default_lang' => 'en', 'proxy_host' => '', 'proxy_port' => '', 'proxy_user' => '', 'proxy_pass' => '' );
$config = array('debug' => 0, 'debug_sql' => 0, 'debug_time' => 0, 'debug_calendar' => 0, 'wsdl_cache' => 1, 'memory_limit' => "256M", 'time_zone' => 'America/New_York', 'memcached' => 0, 'memcached_server' => '', 'default_skin' => 'neoclassic', 'default_lang' => 'en', 'proxy_host' => '', 'proxy_port' => '', 'proxy_user' => '', 'proxy_pass' => '' , 'size_log_file' => 5000000 , 'number_log_file' => 5);
// read the global env.ini configuration file
if ($readGlobalIniFile && ($globalConf = @parse_ini_file($globalIniFile)) !== false) {

View File

@@ -5247,6 +5247,25 @@ class G
$filtro = new InputFilter($tagsArray , $attrArray, $tagsMethod, $attrMethod, $xssAuto);
return $filtro->process($data);
}
/**
* Stores a message in the log file, if the file size exceeds
* specified log file is renamed and a new one is created.
*
* @param type $message
* @param type $pathData
* @param type $file
*/
public function log($message, $pathData = PATH_DATA, $file = 'cron.log')
{
$config = System::getSystemConfiguration();
G::LoadSystem('logger');
$oLogger = logger::getSingleton($pathData, PATH_SEP, $file);
$oLogger->limitFile = $config['number_log_file'];
$oLogger->limitSize = $config['size_log_file'];
$oLogger->write($message);
}
}
/**

View File

@@ -0,0 +1,110 @@
<?php
/**
* class.logger.php
* Stores a message in the log file, if the file size exceeds
* specified log file is renamed and a new one is created.
* $fileName = "filename";
* $fileExtension = ".log";
* $fileSeparatorVersion = "_";
* $limitSize = 1000000;
* 10000000 -> approximately 10 megabytes
* 1000000 -> approximately 1 megabytes
*
* @author Roly Rudy Gutierrez Pinto
* @package gulliver.system
*/
class logger
{
public static $instance = null;
public $limitFile;
public $limitSize;
public $fileName;
public $fileExtension;
public $fileSeparatorVersion;
public $path;
private $fullName;
private $filePath;
public function __construct($pathData, $pathSep, $file = 'cron.log')
{
$this->limitFile = 5;
$this->limitSize = 1000000;
$filename = explode(".", $file);
if (isset($filename[0]) && isset($filename[1])) {
$this->fileName = $filename[0];
$this->fileExtension = '.' . $filename[1];
} else {
$this->fileName = 'cron';
$this->fileExtension = '.log';
}
$this->fileSeparatorVersion = "_";
$this->path = $pathData . "log" . $pathSep;
$this->fullName = $this->fileName . $this->fileExtension;
$this->filePath = $this->path . $this->fullName;
}
public function getSingleton($pathData, $pathSep, $file = 'cron.log')
{
if (self::$instance == null) {
self::$instance = new logger($pathData, $pathSep, $file);
}
return self::$instance;
}
private function getNumberFile($file)
{
$number = str_replace($this->fileExtension, "", $file);
$number = str_replace($this->fileName, "", $number);
$number = str_replace($this->fileSeparatorVersion, "", $number);
return $number;
}
private function isFileLog($file)
{
return !is_dir($file) &&
strpos($file, $this->fileExtension) !== false &&
strpos($file, $this->fileName . $this->fileSeparatorVersion) !== false;
}
private function renameFile()
{
clearstatcache();
if (file_exists($this->filePath)) {
$size = filesize($this->filePath);
if ($size >= $this->limitSize) {
$dir = opendir($this->path);
$ar = array();
while ($file = readdir($dir)) {
if ($this->isFileLog($file)) {
$number = $this->getNumberFile($file);
array_push($ar, $number);
}
}
sort($ar);
$n = count($ar);
for ($i = $n - 1; $i >= 0; $i--) {
$oldName = $this->path . $this->fileName . $this->fileSeparatorVersion . ($ar[$i]) . $this->fileExtension;
$newName = $this->path . $this->fileName . $this->fileSeparatorVersion . ($i + 2) . $this->fileExtension;
if ($i + 1 >= $this->limitFile) {
unlink($oldName);
} else {
rename($oldName, $newName);
}
}
rename($this->filePath, $this->path . $this->fileName . $this->fileSeparatorVersion . 1 . $this->fileExtension);
}
}
}
public function write($message)
{
$this->renameFile();
$file = fopen($this->filePath, "a+");
fwrite($file, $message);
fclose($file);
}
}

View File

@@ -877,12 +877,7 @@ function saveLog($sSource, $sType, $sDescription)
}
G::verifyPath(PATH_DATA . "log" . PATH_SEP, true);
//setExecutionMessage( PATH_DATA."log".PATH_SEP);
$oFile = @fopen(PATH_DATA . "log" . PATH_SEP . "cron.log", "a+");
@fwrite($oFile, date("Y-m-d H:i:s") . " | $sObject | " . $sSource . " | $sType | " . $sDescription . "\n");
@fclose($oFile);
G::log(date("Y-m-d H:i:s") . " | $sObject | " . $sSource . " | $sType | " . $sDescription . "\n", PATH_DATA);
} catch (Exception $e) {
//CONTINUE
}

View File

@@ -336,17 +336,15 @@ function saveLog($sSource, $sType, $sDescription)
global $isDebug;
if ($isDebug)
print date ('H:i:s') . " ($sSource) $sType $sDescription <br>\n";
@fwrite ($oFile, date ('Y-m-d H:i:s') . '(' . $sSource . ') ' . $sDescription . "\n");
G::verifyPath (PATH_DATA . 'log' . PATH_SEP, true);
$message = date ('Y-m-d H:i:s') . '(' . $sSource . ') ' . $sDescription . "\n";
if ($sType == 'action') {
$oFile = @fopen (PATH_DATA . 'log' . PATH_SEP . 'cron.log', 'a+');
G::log($message, PATH_DATA);
}
else {
$oFile = @fopen (PATH_DATA . 'log' . PATH_SEP . 'cronError.log', 'a+');
G::log($message, PATH_DATA, 'cronError.log');
}
@fwrite ($oFile, date ('Y-m-d H:i:s') . '(' . $sSource . ') ' . $sDescription . "\n");
@fclose ($oFile);
}
catch (Exception $oError) {
// CONTINUE

View File

@@ -515,17 +515,15 @@ function saveLog($sSource, $sType, $sDescription)
global $isDebug;
if ($isDebug)
print date ('H:i:s') . " ($sSource) $sType $sDescription <br>\n";
@fwrite ($oFile, date ('Y-m-d H:i:s') . '(' . $sSource . ') ' . $sDescription . "\n");
G::verifyPath (PATH_DATA . 'log' . PATH_SEP, true);
$message = date ('Y-m-d H:i:s') . '(' . $sSource . ') ' . $sDescription . "\n";
if ($sType == 'action') {
$oFile = @fopen (PATH_DATA . 'log' . PATH_SEP . 'cron.log', 'a+');
G::log($message, PATH_DATA);
}
else {
$oFile = @fopen (PATH_DATA . 'log' . PATH_SEP . 'cronError.log', 'a+');
G::log($message, PATH_DATA, 'cronError.log');
}
@fwrite ($oFile, date ('Y-m-d H:i:s') . '(' . $sSource . ') ' . $sDescription . "\n");
@fclose ($oFile);
}
catch (Exception $oError) {
// CONTINUE

View File

@@ -1074,7 +1074,7 @@ class System
}
// default configuration
$config = array ('debug' => 0,'debug_sql' => 0,'debug_time' => 0,'debug_calendar' => 0,'wsdl_cache' => 1,'memory_limit' => "256M", 'time_zone' => 'America/New_York','memcached' => 0,'memcached_server' => '','default_skin' => 'neoclassic','default_lang' => 'en','proxy_host' => '','proxy_port' => '','proxy_user' => '','proxy_pass' => '');
$config = array('debug' => 0, 'debug_sql' => 0, 'debug_time' => 0, 'debug_calendar' => 0, 'wsdl_cache' => 1, 'memory_limit' => "256M", 'time_zone' => 'America/New_York', 'memcached' => 0, 'memcached_server' => '', 'default_skin' => 'neoclassic', 'default_lang' => 'en', 'proxy_host' => '', 'proxy_port' => '', 'proxy_user' => '', 'proxy_pass' => '', 'size_log_file' => 5000000, 'number_log_file' => 5);
// read the global env.ini configuration file
if ($readGlobalIniFile && ($globalConf = @parse_ini_file( $globalIniFile )) !== false) {

View File

@@ -89,6 +89,13 @@ class workspaceTools
$stop = microtime(true);
$final = $stop - $start;
CLI::logging("<*> Updating cache view Process took $final seconds.\n");
$start = microtime(true);
CLI::logging("> Backup log files...\n");
$this->backupLogFiles();
$stop = microtime(true);
$final = $stop - $start;
CLI::logging("<*> Backup log files Process took $final seconds.\n");
}
/**
@@ -1407,5 +1414,19 @@ class workspaceTools
return $result;
}
public function backupLogFiles()
{
clearstatcache();
$path = PATH_DATA . "log" . PATH_SEP;
$filePath = $path . "cron.log";
if (file_exists($filePath)) {
$size = filesize($filePath);
/* 5000000 -> approximately 5 megabytes */
if ($size > 5000000) {
rename($filePath, $filePath . ".bak");
}
}
}
}