public function ajax_flushLog(CM_Params $params, CM_Frontend_JavascriptContainer $handler, CM_Http_Response_View_Ajax $response) { if (!$this->_getAllowedFlush($response->getRender()->getEnvironment())) { throw new CM_Exception_NotAllowed(); } $level = $params->has('level') ? $params->getInt('level') : null; $levelList = $level ? [$level] : null; $type = $params->has('type') ? $params->getInt('type') : null; $logList = new CM_Paging_Log($levelList, $type); $logList->flush(); $response->reloadComponent(); }
/** * @runInSeparateProcess * @preserveGlobalState disabled */ public function testKillChildrenSigKill() { $loopEcho = function () { while (true) { usleep(50 * 1000); echo "hello\n"; } }; $loopEchoStayinAlive = function () { pcntl_signal(SIGTERM, function () { echo "Well, you can tell by the way I use my walk\n I'm a woman's man, no time to talk\n"; }, false); while (true) { usleep(50 * 1000); echo "hello\n"; } }; $process = CM_Process::getInstance(); $process->fork($loopEcho); $process->fork($loopEchoStayinAlive); $pidListBefore = $this->_getChildrenPidList(); $timeStart = microtime(true); $process->killChildren(0.5); $this->assertCount(2, $pidListBefore); $this->assertCount(0, $this->_getChildrenPidList()); $this->assertSameTime(0.65, microtime(true) - $timeStart, 0.15); $logError = new CM_Paging_Log([CM_Log_Logger::ERROR]); $this->assertSame(1, $logError->getCount()); $this->assertContains('killing with signal `9`', $logError->getItem(0)['message']); }
protected function _registerCallbacks() { $this->_registerClockworkCallbacks('1 second', ['CM_Jobdistribution_DelayedQueue::queueOutstanding' => function () { $delayedQueue = $this->getServiceManager()->getDelayedJobQueue(); $delayedQueue->queueOutstanding(); }]); $this->_registerClockworkCallbacks('1 minute', array('CM_Model_User::offlineOld' => function () { CM_Model_User::offlineOld(); }, 'CM_ModelAsset_User_Roles::deleteOld' => function () { CM_ModelAsset_User_Roles::deleteOld(); }, 'CM_Paging_Useragent_Abstract::deleteOlder' => function () { CM_Paging_Useragent_Abstract::deleteOlder(100 * 86400); }, 'CM_File_UserContent_Temp::deleteOlder' => function () { CM_File_UserContent_Temp::deleteOlder(86400); }, 'CM_SVM_Model::deleteOldTrainings' => function () { CM_SVM_Model::deleteOldTrainings(3000); }, 'CM_Paging_Ip_Blocked::deleteOlder' => function () { CM_Paging_Ip_Blocked::deleteOld(); }, 'CM_Captcha::deleteOlder' => function () { CM_Captcha::deleteOlder(3600); }, 'CM_Session::deleteExpired' => function () { CM_Session::deleteExpired(); }, 'CM_MessageStream_Service::synchronize' => function () { CM_Service_Manager::getInstance()->getStreamMessage()->synchronize(); })); if ($this->getServiceManager()->has('janus')) { $this->_registerClockworkCallbacks('1 minute', array('CM_Janus_Service::synchronize' => function () { $this->getServiceManager()->getJanus('janus')->synchronize(); }, 'CM_Janus_Service::checkStreams' => function () { $this->getServiceManager()->getJanus('janus')->checkStreams(); })); } $this->_registerClockworkCallbacks('15 minutes', array('CM_Action_Abstract::aggregate' => function () { CM_Action_Abstract::aggregate(); }, 'CM_Action_Abstract::deleteTransgressionsOlder' => function () { CM_Action_Abstract::deleteTransgressionsOlder(3 * 31 * 86400); }, 'CM_Paging_Log::cleanup' => function () { $allLevelsList = array_values(CM_Log_Logger::getLevels()); foreach (CM_Paging_Log::getClassChildren() as $pagingLogClass) { /** @type CM_Paging_Log $log */ $log = new $pagingLogClass($allLevelsList); $log->cleanUp(); } (new CM_Paging_Log($allLevelsList, false))->cleanUp(); //deletes all untyped records })); if ($this->getServiceManager()->has('maxmind')) { $this->_registerClockworkCallbacks('8 days', array('CMService_MaxMind::upgrade' => function () { try { /** @var CMService_MaxMind $maxMind */ $maxMind = $this->getServiceManager()->get('maxmind', 'CMService_MaxMind'); $maxMind->upgrade(); } catch (Exception $exception) { if (!is_a($exception, 'CM_Exception')) { $exception = new CM_Exception($exception->getMessage(), null, ['file' => $exception->getFile(), 'line' => $exception->getLine(), 'trace' => $exception->getTraceAsString()]); } $exception->setSeverity(CM_Exception::FATAL); throw $exception; } })); } }
/** * @param int $type * @return bool */ public static function isValidType($type) { $type = (int) $type; $childrenTypeList = \Functional\map(CM_Paging_Log::getClassChildren(), function ($className) { /** @type CM_Class_Abstract $className */ return $className::getTypeStatic(); }); return in_array($type, $childrenTypeList); }
public function __construct(array $filterLevelList, $aggregate = false, $ageMax = null) { parent::__construct($filterLevelList, self::getTypeStatic(), $aggregate, $ageMax); }
public function testAggregate() { $client = $this->getServiceManager()->getMongoDb(); $encoder = new CM_Log_Encoder_MongoDb(); $handler = new CM_Log_Handler_MongoDb($client, $encoder, CM_Paging_Log::COLLECTION_NAME); $context1 = new CM_Log_Context(); $context1->setExtra(['bar' => 'quux']); $record1 = new CM_Log_Record(CM_Log_Logger::DEBUG, 'foo', $context1); $context2 = new CM_Log_Context(); $record2 = new CM_Log_Record(CM_Log_Logger::DEBUG, 'baz', $context2); $exception = new CM_Exception_Invalid('Bad news', CM_Exception::WARN, ['baz' => 'bar']); $context3 = new CM_Log_Context(); $context3->setException($exception); $record3 = new CM_Log_Record(CM_Log_Logger::WARNING, 'bar', $context3); //they will not be found $handler->handleRecord($record1); $handler->handleRecord($record2); $handler->handleRecord($record3); CMTest_TH::timeDaysForward(2); //recreate records to correctly set up CM_Log_Record::createdAt $context1 = new CM_Log_Context(); $context1->setExtra(['bar' => 'quux']); $record1 = new CM_Log_Record(CM_Log_Logger::DEBUG, 'foo', $context1); $context3 = new CM_Log_Context(); $context3->setException($exception); $record3 = new CM_Log_Record(CM_Log_Logger::WARNING, 'bar', $context3); $handler->handleRecord($record1); $handler->handleRecord($record3); $handler->handleRecord($record3); CMTest_TH::timeDaysForward(1); $exception2 = new CM_Exception_Invalid('Some info', CM_Exception::FATAL, ['foo' => 'bar']); //recreate records to correctly set up CM_Log_Record::createdAt $context1 = new CM_Log_Context(); $context1->setExtra(['bar' => 'quux']); $record1 = new CM_Log_Record(CM_Log_Logger::DEBUG, 'foo', $context1); $context2 = new CM_Log_Context(); $record2 = new CM_Log_Record(CM_Log_Logger::DEBUG, 'baz', $context2); $context3 = new CM_Log_Context(); $context3->setException($exception); $record3 = new CM_Log_Record(CM_Log_Logger::DEBUG, 'Error bar', $context3); $context4 = new CM_Log_Context(); $context4->setException($exception2); $record4 = new CM_Log_Record(CM_Log_Logger::DEBUG, 'Error bar', $context4); $handler->handleRecord($record2); $handler->handleRecord($record2); $handler->handleRecord($record2); $handler->handleRecord($record3); $handler->handleRecord($record3); $handler->handleRecord($record4); $handler->handleRecord($record1); $handler->handleRecord($record1); $handler->handleRecord($record1); $paging = new CM_Paging_Log([CM_Log_Logger::DEBUG], null, true, 2 * 86400); $this->assertSame(4, $paging->getCount()); $foundRecord1 = $paging->getItem(0); $foundRecord2 = $paging->getItem(1); $foundRecord3 = $paging->getItem(2); $foundRecord4 = $paging->getItem(3); $this->assertSame(4, $foundRecord1['count']); $this->assertSame(3, $foundRecord2['count']); $this->assertSame(2, $foundRecord3['count']); $this->assertSame(1, $foundRecord4['count']); $this->assertSame('foo', $foundRecord1['message']); $this->assertSame('baz', $foundRecord2['message']); $this->assertSame('Error bar', $foundRecord3['message']); $this->assertSame('Bad news', $foundRecord3['exception']['message']); $this->assertSame('Error bar', $foundRecord4['message']); $this->assertSame('Some info', $foundRecord4['exception']['message']); }