Exemplo n.º 1
0
 /**
  * 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;
 }
Exemplo n.º 2
0
 /**
  * @dataProvider getLogLines
  */
 public function test_shouldParseLogLine($expected, $logLine)
 {
     $line = new Line($logLine);
     $parser = new Piwik();
     $this->assertSame($expected, $parser->parse($line));
 }