mirror of
https://github.com/unraid/webgui.git
synced 2026-01-13 05:00:06 -06:00
Memory friendly log file reading and limiting output to 1000 lines. Solves this bug https://forums.unraid.net/bug-reports/stable-releases/66-cant-view-system-log-fatal-memory-error-r210/
35 lines
1.1 KiB
PHP
35 lines
1.1 KiB
PHP
<?PHP
|
|
/* Copyright 2005-2020, Lime Technology
|
|
* Copyright 2012-2020, Bergware International.
|
|
*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public License version 2,
|
|
* as published by the Free Software Foundation.
|
|
*
|
|
* The above copyright notice and this permission notice shall be included in
|
|
* all copies or substantial portions of the Software.
|
|
*/
|
|
?>
|
|
<?
|
|
$docroot = $docroot ?? $_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp';
|
|
require_once "$docroot/webGui/include/ColorCoding.php";
|
|
|
|
$logs = glob($_POST['log'].'*',GLOB_NOSORT);
|
|
usort($logs, create_function('$a,$b', 'return filemtime($a)-filemtime($b);'));
|
|
foreach ($logs as $log) {
|
|
$i=0;
|
|
$line_count = intval(exec("wc -l '$log'"));
|
|
$fh = fopen($log, "r");
|
|
while (($line = fgets($fh)) !== false) {
|
|
$i++;
|
|
if ($i < $line_count - 1000) {
|
|
continue;
|
|
}
|
|
$span = "span class='text'";
|
|
foreach ($match as $type) foreach ($type['text'] as $text) if (preg_match("/$text/i",$line)) {$span = "span class='{$type['class']}'"; break 2;}
|
|
echo "<$span>".htmlspecialchars($line)."</span>";
|
|
}
|
|
fclose($fh);
|
|
}
|
|
?>
|