Add log viewer

This commit is contained in:
Tim 2019-05-29 17:44:49 +02:00
parent 49b9d139ec
commit 858f71e945
4 changed files with 46 additions and 2 deletions

View File

@ -0,0 +1,24 @@
<?php
namespace App\Ardent\LoggerBundle\Controller;
use App\Ardent\LoggerBundle\Service\LoggerService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
class LogViewController extends AbstractController
{
/**
* @Route(path="/view/latest/{amount}")
*/
public function latestLogs(LoggerService $ls, $amount = 10)
{
$logs = $ls->getLatest($amount);
dump(($logs));
return $this->render('@ArdentLogger/errors.html.twig', [
'logs' => $logs,
]);
}
}

View File

@ -0,0 +1,19 @@
{% extends '@ArdentLogger/layout.html.twig' %}
{% block ardent_logger_user_content %}
Error overview <br>
{% for log in logs %}
{# @var log \App\Ardent\LoggerBundle\Entity\LogEntry #}
<div class="card">
<div class="card-body">
<h5 class="card-title">{{ log.levelName }} #{{ log.id }}</h5>
<h6 class="card-subtitle mb-2 text-muted">{{ log.createdAt | date('D, d M y H:i:s') }}</h6>
<p class="card-text">{{ log.message }}</p>
{% for context in log.context %}
<p class="card-text"> > {{ context }}</p>
{% endfor %}
</div>
</div>
{% endfor %}
{% endblock %}

View File

@ -0,0 +1,2 @@
{% block ardent_logger_user_content %}
{% endblock %}

View File

@ -4,7 +4,6 @@ namespace App\Ardent\LoggerBundle\Service;
use App\Ardent\LoggerBundle\Entity\LogEntry;
use Doctrine\ORM\EntityManagerInterface;
use phpDocumentor\Reflection\Types\This;
use Psr\Log\InvalidArgumentException;
class LoggerService
@ -168,7 +167,7 @@ class LoggerService
return $context;
}
public function getLatest($level = self::DEBUG, $amount = 1)
public function getLatest($amount = 1, $level = self::DEBUG)
{
$qb = $this->em->createQueryBuilder();