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;
|
||||
}
|
||||
}
|
||||
|
||||
17
Lib/autoloader.php
Normal file
17
Lib/autoloader.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
ini_set('display_startup_errors', 'On');
|
||||
ini_set('display_errors', 'On');
|
||||
|
||||
// register an autoloader to automatically load classes
|
||||
// the namespace for the class must begin with BSR and
|
||||
// otherwise respect the PSR-4 standard
|
||||
spl_autoload_register(function ($class) {
|
||||
$class = substr($class, strlen('BSR'));
|
||||
$path = sprintf('%s/../%s.php', __DIR__, str_replace('\\', '/', $class));
|
||||
|
||||
if (file_exists($path)) {
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
require $path;
|
||||
}
|
||||
});
|
||||
@@ -485,7 +485,8 @@ class NetBiblio extends WebService
|
||||
public function FindBook($code)
|
||||
{
|
||||
$this->CheckSession();
|
||||
return reset($this->AddBookData(BookSearch::GetBooks(array($code))));
|
||||
$books = $this->AddBookData(BookSearch::GetBooks(array($code)));
|
||||
return reset($books);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
15
index.php
15
index.php
@@ -2,20 +2,7 @@
|
||||
|
||||
namespace BSR;
|
||||
|
||||
ini_set('display_errors', 'On');
|
||||
|
||||
// register an autoloader to automatically load classes
|
||||
// the namespace for the class must begin with BSR and
|
||||
// otherwise respect the PSR-4 standard
|
||||
spl_autoload_register(function ($class) {
|
||||
$class = substr($class, strlen('BSR'));
|
||||
$path = sprintf('%s/%s.php', __DIR__, str_replace('\\', '/', $class));
|
||||
|
||||
if (file_exists($path)) {
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
require $path;
|
||||
}
|
||||
});
|
||||
require_once('Lib/autoloader.php');
|
||||
|
||||
$web = new NetBiblio();
|
||||
$web->Run();
|
||||
|
||||
15
logs.php
Normal file
15
logs.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace BSR;
|
||||
|
||||
use BSR\Lib\Formatter\Html;
|
||||
use BSR\Lib\Logger;
|
||||
|
||||
require_once('Lib/autoloader.php');
|
||||
|
||||
$logs = Logger::getLastLogs();
|
||||
|
||||
echo Html::template(array(
|
||||
'title' => 'Logs',
|
||||
'content' => "<pre>$logs</pre>",
|
||||
));
|
||||
@@ -23,7 +23,8 @@
|
||||
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
|
||||
<ul class="nav navbar-nav">
|
||||
<li><a href="/">Help</a></li>
|
||||
<li><a href="/phpinfo.php">PHPInfo</a></li>
|
||||
<li><a href="logs.php">Logs</a></li>
|
||||
<li><a href="phpinfo.php">PHPInfo</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user