feat: extended log view and searching by error codes
This commit is contained in:
@@ -4,16 +4,27 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Controller\Admin;
|
||||
|
||||
use App\Admin\Field\JsonDataField;
|
||||
use App\Entity\LogEntry;
|
||||
use App\Repository\LogEntryRepository;
|
||||
use App\Service\XmlDumpService;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
|
||||
use League\Flysystem\FilesystemException;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class LogEntryCrudController extends AbstractCrudController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly LogEntryRepository $logEntryRepository,
|
||||
) {
|
||||
}
|
||||
|
||||
public static function getEntityFqcn(): string
|
||||
{
|
||||
return LogEntry::class;
|
||||
@@ -22,7 +33,7 @@ class LogEntryCrudController extends AbstractCrudController
|
||||
public function configureActions(Actions $actions): Actions
|
||||
{
|
||||
$viewDumps = Action::new('viewDumps', 'XML Dumps', 'fa fa-file-code')
|
||||
->linkToRoute('admin_xml_dump_list', static fn (LogEntry $entity): array => ['id' => $entity->getId()])
|
||||
->linkToCrudAction('xmlDumps')
|
||||
->displayIf(static fn (LogEntry $entity): bool => 'bpn' === $entity->getChannel());
|
||||
|
||||
return $actions
|
||||
@@ -42,18 +53,45 @@ class LogEntryCrudController extends AbstractCrudController
|
||||
return $crud
|
||||
->setEntityLabelInSingular('Logeintrag')
|
||||
->setEntityLabelInPlural('Logeinträge')
|
||||
->setDefaultSort(['createdAt' => 'DESC']);
|
||||
->setDefaultSort(['createdAt' => 'DESC'])
|
||||
->setSearchFields(['errorCode', 'message', 'channel', 'extra']);
|
||||
}
|
||||
|
||||
public function configureFields(string $pageName): iterable
|
||||
{
|
||||
return [
|
||||
DateTimeField::new('createdAt', 'Zeitstempel'),
|
||||
TextField::new('errorCode', 'Fehlercode'),
|
||||
TextField::new('username', 'Benutzer'),
|
||||
TextField::new('message', 'Aktion'),
|
||||
TextField::new('requestId', 'Request ID'),
|
||||
TextField::new('uri', 'URI'),
|
||||
];
|
||||
yield DateTimeField::new('createdAt', 'Zeitstempel');
|
||||
yield TextField::new('errorCode', 'Fehlercode')
|
||||
->formatValue(static fn (?string $value): string => $value ?? '-');
|
||||
yield TextField::new('username', 'Benutzer');
|
||||
yield TextField::new('message', 'Aktion');
|
||||
yield TextField::new('requestId', 'Request ID');
|
||||
yield TextField::new('uri', 'URI');
|
||||
yield JsonDataField::new('context', 'Kontext')->onlyOnDetail();
|
||||
yield JsonDataField::new('extra', 'Extra')->onlyOnDetail();
|
||||
}
|
||||
|
||||
public function xmlDumps(Request $request, XmlDumpService $xmlDumpService): Response
|
||||
{
|
||||
$entityId = $request->query->getInt('entityId');
|
||||
if ($entityId <= 0) {
|
||||
throw $this->createNotFoundException('Log entry not found.');
|
||||
}
|
||||
|
||||
$entity = $this->logEntryRepository->find($entityId);
|
||||
if (!$entity instanceof LogEntry) {
|
||||
throw $this->createNotFoundException('Log entry not found.');
|
||||
}
|
||||
|
||||
$dumps = [];
|
||||
try {
|
||||
$dumps = $xmlDumpService->findDumpsForRequestId($entity->getRequestId());
|
||||
} catch (FilesystemException) {
|
||||
}
|
||||
|
||||
return $this->render('admin/xml_dump/list.html.twig', [
|
||||
'logEntry' => $entity,
|
||||
'requestId' => $entity->getRequestId(),
|
||||
'dumps' => $dumps,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user