public function prepare(CM_Frontend_Environment $environment, CM_Frontend_ViewResponse $viewResponse) { $level = $this->_params->has('level') ? $this->_params->getInt('level') : null; if (null !== $level && !CM_Log_Logger::hasLevel($level)) { throw new CM_Exception_InvalidParam('Invalid `level` param'); } $levelList = $level ? [$level] : null; $type = $this->_params->has('type') ? $this->_params->getInt('type') : null; if (null !== $type && !CM_Paging_Log::isValidType($type)) { throw new CM_Exception_InvalidParam('Invalid `type` param'); } $aggregate = $this->_params->has('aggregate') ? $this->_params->getInt('aggregate') : null; $urlPage = $this->_params->has('urlPage') ? $this->_params->getString('urlPage') : null; $urlParams = $this->_params->has('urlParams') ? $this->_params->getArray('urlParams') : null; $aggregationPeriod = $aggregate; if (0 === $aggregationPeriod) { $deployStamp = CM_App::getInstance()->getDeployVersion(); $aggregationPeriod = time() - $deployStamp; } $logList = new CM_Paging_Log($levelList, $type, (bool) $aggregationPeriod, $aggregationPeriod); $logList->setPage($this->_params->getPage(), $this->_params->getInt('count', 50)); $viewResponse->setData(['level' => $level, 'type' => $type, 'logList' => $logList, 'aggregate' => $aggregate, 'aggregationPeriod' => $aggregationPeriod, 'aggregationPeriodList' => array(3600, 86400, 7 * 86400, 31 * 86400), 'urlPage' => $urlPage, 'urlParams' => $urlParams, 'levelMap' => array_flip(CM_Log_Logger::getLevels())]); $viewResponse->getJs()->setProperty('level', $level); $viewResponse->getJs()->setProperty('type', $type); }
/** * @param array $filterLevelList * @param int|boolean|null $filterType * @param boolean|null $aggregate * @param int|null $ageMax * @throws CM_Exception_Invalid */ public function __construct(array $filterLevelList = null, $filterType = null, $aggregate = null, $ageMax = null) { if (null !== $filterLevelList) { foreach ($filterLevelList as $level) { $level = (int) $level; if (!CM_Log_Logger::hasLevel($level)) { throw new CM_Exception_Invalid('Log level does not exist.', null, ['level' => $level]); } } } if (null !== $filterType && false !== $filterType && !self::isValidType((int) $filterType)) { throw new CM_Exception_Invalid('Type is not a children of CM_Paging_Log.'); } if (null !== $ageMax) { $ageMax = (int) $ageMax; } $this->_filterLevelList = $filterLevelList; $this->_filterType = $filterType; $this->_ageMax = $ageMax; $criteria = $this->_getCriteria(); if (true === $aggregate) { $aggregate = [['$match' => $criteria], ['$group' => ['_id' => ['level' => '$level', 'message' => '$message', 'exception_message' => '$context.exception.message', 'exception_class' => '$context.exception.class', 'exception_line' => '$context.exception.line', 'exception_file' => '$context.exception.file'], 'count' => ['$sum' => 1], 'createdAt' => ['$max' => '$createdAt'], 'exception' => ['$last' => '$context.exception']]], ['$sort' => ['count' => -1]], ['$project' => ['level' => '$_id.level', 'message' => '$_id.message', 'exception' => '$exception', 'count' => '$count', 'createdAt' => '$createdAt', '_id' => false]]]; $source = new CM_PagingSource_MongoDb(self::COLLECTION_NAME, null, null, $aggregate); } else { $sorting = empty($criteria) ? ['_id' => -1] : ['createdAt' => -1]; $source = new CM_PagingSource_MongoDb(self::COLLECTION_NAME, $criteria, null, null, $sorting); } parent::__construct($source); }
/** * @param int $level * @throws CM_Exception_Invalid */ public function setMinLevel($level) { $level = (int) $level; if (CM_Log_Logger::hasLevel($level)) { $this->_minLevel = $level; } }
/** * @param int $level * @param string $message * @param CM_Log_Context $context * @throws CM_Exception_Invalid */ public function __construct($level, $message, CM_Log_Context $context) { $level = (int) $level; $message = (string) $message; if (!CM_Log_Logger::hasLevel($level)) { throw new CM_Exception_Invalid('Log level does not exist.', null, ['level' => $level]); } $this->_level = $level; $this->_message = $message; $this->_context = $context; $this->_createdAt = CM_Util::createDateTimeWithMillis(); }
public function testStaticLogLevelMethods() { $this->assertSame('INFO', CM_Log_Logger::getLevelName(CM_Log_Logger::INFO)); $this->assertNotEmpty(CM_Log_Logger::getLevels()); $this->assertTrue(CM_Log_Logger::hasLevel(CM_Log_Logger::INFO)); $this->assertFalse(CM_Log_Logger::hasLevel(666)); }