Show logs through the web interface
This commit is contained in:
@@ -87,4 +87,38 @@ class Logger {
|
||||
public static function data() {
|
||||
return self::$data;
|
||||
}
|
||||
}
|
||||
|
||||
public static function getLastLogs($offset = null) {
|
||||
$file = Configuration::get('log.file');
|
||||
if(! file_exists($file)) {
|
||||
return 'No log yet !';
|
||||
}
|
||||
|
||||
$f = fopen($file, 'r');
|
||||
|
||||
$len = 1024;
|
||||
|
||||
fseek($f, 0, SEEK_END);
|
||||
$size = ftell($f);
|
||||
if(is_null($offset) || $offset > $size) {
|
||||
$offset = $size - $len;
|
||||
}
|
||||
$offset = max(0, $offset);
|
||||
|
||||
fseek($f, $offset);
|
||||
|
||||
// remove the first line that may be incomplete
|
||||
$buffer = fread($f, $len);
|
||||
$buffer = explode("\n", $buffer);
|
||||
array_shift($buffer);
|
||||
$buffer = implode("\n", $buffer);
|
||||
// continue reading until the end of the file
|
||||
while(! feof($f)) {
|
||||
$buffer .= fread($f, $len);
|
||||
}
|
||||
|
||||
fclose($f);
|
||||
|
||||
return $buffer;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user