Merge pull request #2164 from gproly/BUG-13506
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:
@@ -85,7 +85,7 @@ class Bootstrap
|
|||||||
}
|
}
|
||||||
|
|
||||||
// default configuration
|
// 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
|
// read the global env.ini configuration file
|
||||||
if ($readGlobalIniFile && ($globalConf = @parse_ini_file($globalIniFile)) !== false) {
|
if ($readGlobalIniFile && ($globalConf = @parse_ini_file($globalIniFile)) !== false) {
|
||||||
|
|||||||
@@ -5247,6 +5247,25 @@ class G
|
|||||||
$filtro = new InputFilter($tagsArray , $attrArray, $tagsMethod, $attrMethod, $xssAuto);
|
$filtro = new InputFilter($tagsArray , $attrArray, $tagsMethod, $attrMethod, $xssAuto);
|
||||||
return $filtro->process($data);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
110
gulliver/system/class.logger.php
Normal file
110
gulliver/system/class.logger.php
Normal 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 = pathinfo($file);
|
||||||
|
if (isset($filename['filename']) && isset($filename['extension'])) {
|
||||||
|
$this->fileName = $filename['filename'];
|
||||||
|
$this->fileExtension = '.' . $filename['extension'];
|
||||||
|
} 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -895,12 +895,7 @@ function saveLog($sSource, $sType, $sDescription)
|
|||||||
}
|
}
|
||||||
|
|
||||||
G::verifyPath(PATH_DATA . "log" . PATH_SEP, true);
|
G::verifyPath(PATH_DATA . "log" . PATH_SEP, true);
|
||||||
|
G::log(date("Y-m-d H:i:s") . " | $sObject | " . $sSource . " | $sType | " . $sDescription . "\n", PATH_DATA);
|
||||||
//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);
|
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
//CONTINUE
|
//CONTINUE
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -336,17 +336,15 @@ function saveLog($sSource, $sType, $sDescription)
|
|||||||
global $isDebug;
|
global $isDebug;
|
||||||
if ($isDebug)
|
if ($isDebug)
|
||||||
print date ('H:i:s') . " ($sSource) $sType $sDescription <br>\n";
|
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);
|
G::verifyPath (PATH_DATA . 'log' . PATH_SEP, true);
|
||||||
|
$message = date ('Y-m-d H:i:s') . '(' . $sSource . ') ' . $sDescription . "\n";
|
||||||
if ($sType == 'action') {
|
if ($sType == 'action') {
|
||||||
$oFile = @fopen (PATH_DATA . 'log' . PATH_SEP . 'cron.log', 'a+');
|
G::log($message, PATH_DATA);
|
||||||
}
|
}
|
||||||
else {
|
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) {
|
catch (Exception $oError) {
|
||||||
// CONTINUE
|
// CONTINUE
|
||||||
|
|||||||
@@ -515,17 +515,15 @@ function saveLog($sSource, $sType, $sDescription)
|
|||||||
global $isDebug;
|
global $isDebug;
|
||||||
if ($isDebug)
|
if ($isDebug)
|
||||||
print date ('H:i:s') . " ($sSource) $sType $sDescription <br>\n";
|
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);
|
G::verifyPath (PATH_DATA . 'log' . PATH_SEP, true);
|
||||||
|
$message = date ('Y-m-d H:i:s') . '(' . $sSource . ') ' . $sDescription . "\n";
|
||||||
if ($sType == 'action') {
|
if ($sType == 'action') {
|
||||||
$oFile = @fopen (PATH_DATA . 'log' . PATH_SEP . 'cron.log', 'a+');
|
G::log($message, PATH_DATA);
|
||||||
}
|
}
|
||||||
else {
|
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) {
|
catch (Exception $oError) {
|
||||||
// CONTINUE
|
// CONTINUE
|
||||||
|
|||||||
@@ -1084,7 +1084,7 @@ class System
|
|||||||
}
|
}
|
||||||
|
|
||||||
// default configuration
|
// 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
|
// read the global env.ini configuration file
|
||||||
if ($readGlobalIniFile && ($globalConf = @parse_ini_file( $globalIniFile )) !== false) {
|
if ($readGlobalIniFile && ($globalConf = @parse_ini_file( $globalIniFile )) !== false) {
|
||||||
|
|||||||
@@ -89,6 +89,13 @@ class workspaceTools
|
|||||||
$stop = microtime(true);
|
$stop = microtime(true);
|
||||||
$final = $stop - $start;
|
$final = $stop - $start;
|
||||||
CLI::logging("<*> Updating cache view Process took $final seconds.\n");
|
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");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1424,5 +1431,21 @@ class workspaceTools
|
|||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function backupLogFiles()
|
||||||
|
{
|
||||||
|
$config = System::getSystemConfiguration();
|
||||||
|
|
||||||
|
clearstatcache();
|
||||||
|
$path = PATH_DATA . "log" . PATH_SEP;
|
||||||
|
$filePath = $path . "cron.log";
|
||||||
|
if (file_exists($filePath)) {
|
||||||
|
$size = filesize($filePath);
|
||||||
|
/* $config['size_log_file'] has the value 5000000 -> approximately 5 megabytes */
|
||||||
|
if ($size > $config['size_log_file']) {
|
||||||
|
rename($filePath, $filePath . ".bak");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user