/** * Get log entries. * * Latest log entries are returned first. * * @param string $query A search query. If given, the search is performed case insensitive and query is interpreted * as a regular expression. Characters like `[` might need to be escaped as `\[`. * @param string|false $source The log reader to use. Either 'file' or 'database'. * By default we try to detect the best reader automatically. * @param int $page The page that should be returned. * @param int $limitPerPage Defines how many log entries should be returned per page. * @return array * @throws \Exception Eg if the source cannot be chosen automatically. */ public function getLogEntries($query = '', $source = false, $page = 0, $limitPerPage = 10) { Piwik::checkUserHasSuperUserAccess(); $logReaderFactory = new LogReaderFactory(); $reader = $logReaderFactory->make($source); $log = new Log($reader); $result = $log->find(new Query($query), new Result($limitPerPage, $page)); $parser = new PiwikParser(); $return = array(); foreach ($result->getLogLines() as $logLine) { $return[] = $parser->parse($logLine); } return $return; }
/** * @expectedException \Exception * @expectedExceptionMessage No source specified, please specify one of: file, database */ public function test_make_shouldThrowException_IfNoSourceSpecified_AndManyWritersConfigured() { $this->setLogWriters(array('file', 'database')); $this->factory->make(false); }