From 20ab59b570439930b40f87d7818a5cef96f759fe Mon Sep 17 00:00:00 2001 From: Mzhelskiy Maxim Date: Wed, 27 Apr 2011 07:44:28 +0000 Subject: [PATCH] fix cron and logger --- config/config.php | 1 + engine/classes/Cron.class.php | 13 ++++++++++--- engine/modules/logger/Logger.class.php | 8 ++++++++ include/cron/notify.php | 12 +++++------- include/cron/template.php | 7 ++----- 5 files changed, 26 insertions(+), 15 deletions(-) diff --git a/config/config.php b/config/config.php index cf2148ce..7b903294 100644 --- a/config/config.php +++ b/config/config.php @@ -113,6 +113,7 @@ $config['sys']['logs']['sql_query'] = false; // логирова $config['sys']['logs']['sql_query_file'] = 'sql_query.log'; // файл лога SQL запросов $config['sys']['logs']['sql_error'] = true; // логировать или нет ошибки SQl $config['sys']['logs']['sql_error_file'] = 'sql_error.log'; // файл лога ошибок SQL +$config['sys']['logs']['cron'] = true; // логировать или нет cron скрипты $config['sys']['logs']['cron_file'] = 'cron.log'; // файл лога запуска крон-процессов $config['sys']['logs']['profiler'] = false; // логировать или нет профилирование процессов $config['sys']['logs']['profiler_file'] = 'profiler.log'; // файл лога профилирования процессов diff --git a/engine/classes/Cron.class.php b/engine/classes/Cron.class.php index 3bb023cc..f38f9d93 100644 --- a/engine/classes/Cron.class.php +++ b/engine/classes/Cron.class.php @@ -36,9 +36,10 @@ class Cron extends Object { * * @var string */ - protected $sProcessName='Cron'; + protected $sProcessName; public function __construct($sLockFile=null) { + $this->sProcessName=get_class($this); $this->oEngine=Engine::getInstance(); /** * Инициализируем ядро @@ -63,8 +64,10 @@ class Cron extends Object { * @return */ public function Log($sMsg) { - $sMsg=$this->sProcessName.': '.$sMsg; - $this->oEngine->Logger_Notice($sMsg); + if (Config::Get('sys.logs.cron')) { + $sMsg=$this->sProcessName.': '.$sMsg; + $this->oEngine->Logger_Notice($sMsg); + } } /** @@ -129,5 +132,9 @@ class Cron extends Object { public function Client(){ throw new Exception('Call undefined client function'); } + + public function __call($sName,$aArgs) { + return $this->oEngine->_CallModule($sName,$aArgs); + } } ?> \ No newline at end of file diff --git a/engine/modules/logger/Logger.class.php b/engine/modules/logger/Logger.class.php index c013142a..e8e93736 100644 --- a/engine/modules/logger/Logger.class.php +++ b/engine/modules/logger/Logger.class.php @@ -63,6 +63,12 @@ class ModuleLogger extends Module { * @var int */ protected $iSizeForRotate=1000000; + /** + * Случайное число + * + * @var unknown_type + */ + protected $iRandom; /** @@ -72,6 +78,7 @@ class ModuleLogger extends Module { public function Init() { $this->sPathLogs=Config::Get('path.root.server').'/logs/'; $this->SetFileName(Config::Get('sys.logs.file')); + $this->iRandom=rand(1000,9999); } /** @@ -199,6 +206,7 @@ class ModuleLogger extends Module { */ $msgOut ='['.date("Y-m-d H:i:s").']'; $msgOut.='['.getmypid().']'; + $msgOut.='['.$this->iRandom.']'; $msgOut.='['.$this->logLevel[$key].']'; $msgOut.='['.$msg.']'; /** diff --git a/include/cron/notify.php b/include/cron/notify.php index 57a8b3f6..67f7ba22 100644 --- a/include/cron/notify.php +++ b/include/cron/notify.php @@ -14,7 +14,6 @@ * --------------------------------------------------------- */ -define('SYS_HACKER_CONSOLE',false); $sDirRoot=dirname(dirname(dirname(__FILE__))); set_include_path(get_include_path().PATH_SEPARATOR.$sDirRoot); @@ -24,15 +23,14 @@ require_once($sDirRoot."/config/loader.php"); require_once($sDirRoot."/engine/classes/Cron.class.php"); class NotifyCron extends Cron { - protected $sProcessName='NotifyCron'; /** * Выбираем пул заданий и рассылаем по ним e-mail */ public function Client() { - $aNotifyTasks = $this->oEngine->Notify_GetTasksDelayed(Config::Get('module.notify.per_process')); + $aNotifyTasks = $this->Notify_GetTasksDelayed(Config::Get('module.notify.per_process')); if(empty($aNotifyTasks)) { - print PHP_EOL."No tasks are found."; + $this->Log("No tasks are found."); return; } /** @@ -40,14 +38,14 @@ class NotifyCron extends Cron { */ $aArrayId=array(); foreach ($aNotifyTasks as $oTask) { - $this->oEngine->Notify_SendTask($oTask); + $this->Notify_SendTask($oTask); $aArrayId[]=$oTask->getTaskId(); } - print PHP_EOL."Send notify: ".count($aArrayId); + $this->Log("Send notify: ".count($aArrayId)); /** * Удаляем отработанные задания */ - $this->oEngine->Notify_DeleteTaskByArrayId($aArrayId); + $this->Notify_DeleteTaskByArrayId($aArrayId); } } diff --git a/include/cron/template.php b/include/cron/template.php index 82a28495..f8308fb9 100644 --- a/include/cron/template.php +++ b/include/cron/template.php @@ -14,7 +14,6 @@ * --------------------------------------------------------- */ -define('SYS_HACKER_CONSOLE',false); $sDirRoot=dirname(dirname(dirname(__FILE__))); set_include_path(get_include_path().PATH_SEPARATOR.$sDirRoot); @@ -24,19 +23,17 @@ require_once($sDirRoot."/config/loader.php"); require_once($sDirRoot."/engine/classes/Cron.class.php"); class TemplateCacheCleanCron extends Cron { - protected $sProcessName='TemplateCacheCleanCron'; /** * Находим все кеш-файлы js и css и удаляем их с сервера */ public function Client() { - $sDir = Config::Get('path.smarty.cache'); /** * Выбираем все файлы кеша */ - $aFiles = glob($sDir. DIRECTORY_SEPARATOR ."*.{css,js}", GLOB_BRACE); + $aFiles = glob(Config::Get('path.smarty.cache'). DIRECTORY_SEPARATOR ."*\*.{css,js}", GLOB_BRACE); if (!$aFiles) $aFiles=array(); - print PHP_EOL."Cache files count: ".count($aFiles); + $this->Log("Cache files count: ".count($aFiles)); foreach ($aFiles as $sFilePath) { @unlink($sFilePath);