function NWPrintLog($offset = 0, $maxLenght = false, $date = "today", $path = "./Logs/") { if ($date = "today") { $date = strtotime(date("d-m-y", time())); } $file = "log_" . $date . ".txt"; if ($logRaw = file($path . $file)) { $logLinesCount = count($logRaw); } else { if (DEBUG) { NWWriteLog("Requested log does not exist."); } return false; } if ($offset > $logLinesCount or $offset < 0) { if (DEBUG) { NWWriteLog("Parameter offset failed."); } return false; } if (!$maxLenght) { $maxLenght = $logLinesCount - 1; } if ($maxLenght > $logLinesCount or $maxLenght < 0) { if (DEBUG) { NWWriteLog("Parameter maxLenght failed."); } return false; } $logString = ""; foreach ($logRaw as $key => $value) { if ($key >= $offset and $key <= $maxLenght) { $logString .= $value; } } return $logString; }
function NWReadFileToLine($file, $lineEnd = 0, $lineStart = 0, $path = "./") { $lineEnd = $lineEnd - 1; if (!($path = NWPathComplete($path))) { if (DEBUG) { NWWriteLog("Couldn't resolve path."); } return false; } $linesArr = file($path . $file); $maxLines = count($linesArr); if ($lineEnd <= 0 or $lineEnd < $lineStart) { $lineEnd = $maxLines; if (DEBUG) { NWWriteLog("Line parameters are not as expected #1. Modifying."); } } if ($lineEnd > $maxLines) { $lineEnd = $maxLines; if (DEBUG) { NWWriteLog("Line parameters are not as expected #2 (End: {$linesEnd} but Max: {$maxLines}). Modifying."); } } if ($lineStart > $maxLines) { $lineEnd = $lineEnd - 1; if (DEBUG) { NWWriteLog("Line parameters are not as expected #2. Modifying."); } } for ($i = $lineStart; $i <= $lineEnd; $i++) { $returnArray[] = $linesArr[$i]; } return implode("", $returnArray); }
protected function addError($number, $message) { $this->errorArray[] = array($number => $message); NWWriteLog("{$number} {$message}", debug_backtrace()); return true; }