/** * Fetches the latest entries from the current systemlog. * The entries can be limited by the optional param latestEntry. * If given, only entries created after the passed date will be returned. * The format of latestEntry is similar to the date returned, so YYYY-MM-DD HH:MM:SS * The structure is returned like: * <entries> * <entry> * <level></level> * <date></date> * <session></session> * <content></content> * </entry> * </entries> * * @return string * @permissions right3 */ protected function actionSystemLog() { $strReturn = ""; $intStartDate = false; if ($this->getParam("latestEntry") != "") { $intStartDate = strtotime($this->getParam("latestEntry")); } //read the last few lines $objFile = new class_filesystem(); $arrDetails = $objFile->getFileDetails("/system/debug/systemlog.log"); $intOffset = 0; $bitSkip = false; if ($arrDetails["filesize"] > 20000) { $intOffset = $arrDetails["filesize"] - 20000; $bitSkip = true; } $objFile->openFilePointer("/system/debug/systemlog.log", "r"); //forward to the new offset, skip entry if ($intOffset > 0) { $objFile->setFilePointerOffset($intOffset); } $arrRows = array(); $strRow = $objFile->readLineFromFile(); while ($strRow !== false) { if (!$bitSkip && trim($strRow) > 0) { $arrRows[] = $strRow; } $bitSkip = false; $strRow = $objFile->readLineFromFile(); } $objFile->closeFilePointer(); $strReturn .= "<entries>\n"; $arrRows = array_reverse($arrRows); foreach ($arrRows as $strSingleRow) { //parse entry $strDate = uniSubstr($strSingleRow, 0, 19); $strSingleRow = uniSubstr($strSingleRow, 20); $intTempPos = uniStrpos($strSingleRow, " "); $strLevel = uniSubstr($strSingleRow, 0, $intTempPos); $strSingleRow = uniSubstr($strSingleRow, $intTempPos + 1); $intTempPos = uniStrpos($strSingleRow, ")") + 1; $strSession = uniSubstr($strSingleRow, 0, $intTempPos); $strLogEntry = uniSubstr($strSingleRow, $intTempPos); if ($intStartDate !== false) { $intCurDate = strtotime($strDate); if ($intStartDate >= $intCurDate) { continue; } } $strReturn .= "\t<entry>\n"; $strReturn .= "\t\t<level>" . $strLevel . "</level>\n"; $strReturn .= "\t\t<date>" . $strDate . "</date>\n"; $strReturn .= "\t\t<session>" . $strSession . "</session>\n"; $strReturn .= "\t\t<content>" . xmlSafeString(strip_tags($strLogEntry)) . "</content>\n"; $strReturn .= "\t</entry>\n"; } $strReturn .= "</entries>"; return $strReturn; }