Improve looks
This commit is contained in:
@ -1,16 +1,20 @@
|
||||
<?php
|
||||
namespace ProVM\Common\Controller;
|
||||
|
||||
use ProVM\Common\Service\Logs;
|
||||
use SplFileInfo;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Slim\Views\Blade as View;
|
||||
use ProVM\Common\Service\Logs;
|
||||
|
||||
class Base
|
||||
{
|
||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, View $view, Logs $service): ResponseInterface
|
||||
{
|
||||
$files = $service->getFiles();
|
||||
usort($files, function(SplFileInfo $a, SplFileInfo $b) {
|
||||
return $b->getCTime() - $a->getCTime();
|
||||
});
|
||||
return $view->render($response, 'home', compact('files'));
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
<?php
|
||||
namespace ProVM\Common\Service;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use SplFileInfo;
|
||||
use ProVM\Logview\Log\File;
|
||||
|
||||
class Logs
|
||||
@ -38,7 +40,9 @@ class Logs
|
||||
}
|
||||
public function get(string $log_file): File
|
||||
{
|
||||
$content = \Safe\file_get_contents(implode(DIRECTORY_SEPARATOR, [$this->getFolder(), $log_file]));
|
||||
return (new File())->setFilename($log_file)->setContent($content);
|
||||
$filename = implode(DIRECTORY_SEPARATOR, [$this->getFolder(), $log_file]);
|
||||
$file_info = new SplFileInfo($filename);
|
||||
$content = \Safe\file_get_contents($filename);
|
||||
return (new File())->setFilename($log_file)->setDate((new DateTimeImmutable())->setTimestamp($file_info->getCTime()))->setContent($content);
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
<div class="ui container">
|
||||
<div class="ui list">
|
||||
@foreach ($files as $file)
|
||||
<a class="item" href="{{$urls->base}}/log/{{urlencode($file->getBasename())}}">{{$file->getBasename()}}</a>
|
||||
<a class="item" href="{{$urls->base}}/log/{{urlencode($file->getBasename())}}">[{{(new DateTimeImmutable)->setTimestamp($file->getCTime())->format('Y-m-d H:i:s')}}] {{$file->getBasename()}}</a>
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
|
@ -1,5 +1,5 @@
|
||||
@extends('layout.base')
|
||||
|
||||
@section('page_title')
|
||||
File {{$log->getFilename()}}
|
||||
Log File
|
||||
@endsection
|
||||
|
@ -2,54 +2,58 @@
|
||||
|
||||
@section('page_content')
|
||||
<div class="ui container">
|
||||
<h3 class="ui header">Logs</h3>
|
||||
</div>
|
||||
<div class="ui accordion">
|
||||
@foreach($log->getLogs() as $line)
|
||||
<div class="title {{strtolower($line->getSeverity())}}">
|
||||
<i class="dropdown icon"></i>
|
||||
{{$line->getDate()->format('Y-m-d H:i:s.u')}} - {{$line->getSeverity()}}
|
||||
</div>
|
||||
<div class="content">
|
||||
<div class="ui fluid card">
|
||||
<div class="content">
|
||||
<div class="header">
|
||||
<span class="{{strtolower($line->getSeverity())}}" style="padding: 1ex 1em;">
|
||||
<i class="bug icon"></i>
|
||||
{{$line->getChannel()}}.{{$line->getSeverity()}}
|
||||
</span>
|
||||
<h3 class="ui header">Log File: {{$log->getFilename()}}</h3>
|
||||
<h5 class="ui header">{{$log->getDate()->format('Y-m-d H:i:s')}}</h5>
|
||||
<div class="ui accordion">
|
||||
@foreach($log->getLogs() as $line)
|
||||
<div class="title">
|
||||
<i class="dropdown icon"></i>
|
||||
<span class="{{strtolower($line->getSeverity())}}" style="padding-left: 1ex;padding-right: 1ex;">
|
||||
{{$line->getDate()->format('Y-m-d H:i:s.u')}} - {{$line->getSeverity()}}
|
||||
</span>
|
||||
</div>
|
||||
<div class="content">
|
||||
<div class="ui fluid basic card">
|
||||
<div class="content">
|
||||
<div class="header">
|
||||
<span class="{{strtolower($line->getSeverity())}}" style="padding: 1ex 1em;">
|
||||
<i class="bug icon"></i>
|
||||
{{$line->getChannel()}}.{{$line->getSeverity()}}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="content">
|
||||
<div class="description">
|
||||
{{$line->getMessage()}}
|
||||
</div>
|
||||
@if ($line->hasStack())
|
||||
<div class="ui small feed">
|
||||
@foreach ($line->getStack() as $stack)
|
||||
<div class="event">
|
||||
<div class="content">
|
||||
{{$stack}}
|
||||
<div class="content">
|
||||
<div class="description">
|
||||
{{$line->getMessage()}}
|
||||
</div>
|
||||
@if ($line->hasStack())
|
||||
<div class="ui small feed">
|
||||
@foreach ($line->getStack() as $stack)
|
||||
<div class="event">
|
||||
<div class="content">
|
||||
{{$stack}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endforeach
|
||||
@endforeach
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
@if ($line->hasContext())
|
||||
<div class="extra content">
|
||||
{{$line->getContext()}}
|
||||
<div class="meta">{{$line->getExtra()}}</div>
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
@if ($line->hasContext())
|
||||
<div class="extra content">
|
||||
{{$line->getContext()}}
|
||||
<div class="meta">{{$line->getExtra()}}</div>
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
@endforeach
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@push('page_styles')
|
||||
<style>
|
||||
body {overflow-y:scroll;}
|
||||
@foreach ($levels as $level => $colors)
|
||||
.{{$level}} {background-color: {{$colors->background}}; color: {{$colors->text}};}
|
||||
@endforeach
|
||||
@ -58,6 +62,7 @@
|
||||
|
||||
@push('page_scripts')
|
||||
<script type="text/javascript">
|
||||
|
||||
$('.accordion').accordion()
|
||||
</script>
|
||||
@endpush
|
||||
|
@ -16,7 +16,7 @@ class Log
|
||||
|
||||
public function getDate(): DateTimeInterface
|
||||
{
|
||||
return $this->dateTime;
|
||||
return $this->dateTime ?? new DateTimeImmutable();
|
||||
}
|
||||
public function getChannel(): string
|
||||
{
|
||||
@ -103,7 +103,9 @@ class Log
|
||||
|
||||
$regex = "/\[(?P<date>.*)\]\s(?<channel>\w*)\.(?<severity>\w*):\s(?<message>.*)\s[\[|\{](?<context>.*)[\]|\}]\s\[(?<extra>.*)\]/";
|
||||
preg_match($regex, $content, $matches);
|
||||
$log->setDate(DateTimeImmutable::createFromFormat('Y-m-d\TH:i:s.uP', $matches['date']));
|
||||
if (isset($matches['date'])) {
|
||||
$log->setDate(DateTimeImmutable::createFromFormat('Y-m-d\TH:i:s.uP', $matches['date']));
|
||||
}
|
||||
$log->setChannel($matches['channel']);
|
||||
$log->setSeverity($matches['severity']);
|
||||
$message = $matches['message'];
|
||||
|
@ -1,18 +1,23 @@
|
||||
<?php
|
||||
namespace ProVM\Logview\Log;
|
||||
|
||||
use Generator;
|
||||
use DateTimeInterface;
|
||||
use ProVM\Logview\Log;
|
||||
|
||||
class File
|
||||
{
|
||||
protected string $filename;
|
||||
protected DateTimeInterface $dateTime;
|
||||
protected string $content;
|
||||
|
||||
public function getFilename(): string
|
||||
{
|
||||
return $this->filename;
|
||||
}
|
||||
public function getDate(): DateTimeInterface
|
||||
{
|
||||
return $this->dateTime;
|
||||
}
|
||||
public function getContent(): string
|
||||
{
|
||||
return $this->content;
|
||||
@ -23,6 +28,11 @@ class File
|
||||
$this->filename = $filename;
|
||||
return $this;
|
||||
}
|
||||
public function setDate(DateTimeInterface $dateTime): File
|
||||
{
|
||||
$this->dateTime = $dateTime;
|
||||
return $this;
|
||||
}
|
||||
public function setContent(string $content): File
|
||||
{
|
||||
$this->content = $content;
|
||||
|
Reference in New Issue
Block a user