/** * Return the given number of entries from the end of log file * * @param string $name Name of log * @param int $limit Number of entries to retrieve (default = 10) * @return array * @todo add pagination capability * */ public function get($name, $limit = 10) { $log = new FileLog($this->getFilename($name)); $chunkSize = $limit * 255; // 255 = guesstimate of average line length $lines = array(); $cnt = 0; $lastCnt = 0; while (1) { $lines = $log->get($chunkSize); $cnt = count($lines); if (!$cnt || $cnt >= $limit || $lastCnt == $cnt) { break; } $lastCnt = $cnt; $chunkSize += ($limit - $cnt) * $log->getMaxLineLength(); } if ($cnt > $limit) { $lines = array_slice($lines, 0, $limit); } return $lines; }