feat: extended log view and searching by error codes
This commit is contained in:
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace DoctrineMigrations;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
|
use Doctrine\Migrations\AbstractMigration;
|
||||||
|
|
||||||
|
final class Version20260320071724 extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function getDescription(): string
|
||||||
|
{
|
||||||
|
return 'Add error_code column and index to log_entry table';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function up(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->addSql('ALTER TABLE log_entry ADD error_code VARCHAR(12) DEFAULT NULL');
|
||||||
|
$this->addSql('CREATE INDEX IDX_LOG_ENTRY_ERROR_CODE ON log_entry (error_code)');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->addSql('DROP INDEX IDX_LOG_ENTRY_ERROR_CODE ON log_entry');
|
||||||
|
$this->addSql('ALTER TABLE log_entry DROP error_code');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Command;
|
||||||
|
|
||||||
|
use App\Entity\LogEntry;
|
||||||
|
use App\Repository\LogEntryRepository;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
use Symfony\Component\Console\Attribute\AsCommand;
|
||||||
|
use Symfony\Component\Console\Command\Command;
|
||||||
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||||
|
|
||||||
|
#[AsCommand(
|
||||||
|
name: 'app:log-entry:backfill-error-codes',
|
||||||
|
description: 'Backfills error_code column from extra data in existing log entries'
|
||||||
|
)]
|
||||||
|
class LogEntryBackfillErrorCodesCommand extends Command
|
||||||
|
{
|
||||||
|
private const BATCH_SIZE = 100;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
private readonly LogEntryRepository $logEntryRepository,
|
||||||
|
private readonly EntityManagerInterface $entityManager,
|
||||||
|
) {
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||||
|
{
|
||||||
|
$io = new SymfonyStyle($input, $output);
|
||||||
|
|
||||||
|
$io->info('Starting backfill of error codes...');
|
||||||
|
|
||||||
|
$totalProcessed = 0;
|
||||||
|
$totalUpdated = 0;
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
$entries = $this->logEntryRepository->createQueryBuilder('l')
|
||||||
|
->where('l.errorCode IS NULL')
|
||||||
|
->andWhere('l.extra LIKE :pattern')
|
||||||
|
->setParameter('pattern', '%error_code%')
|
||||||
|
->orderBy('l.id', 'ASC')
|
||||||
|
->setMaxResults(self::BATCH_SIZE)
|
||||||
|
->getQuery()
|
||||||
|
->getResult();
|
||||||
|
|
||||||
|
if ([] === $entries) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($entries as $entry) {
|
||||||
|
/** @var LogEntry $entry */
|
||||||
|
$extra = $entry->getExtra();
|
||||||
|
if (isset($extra['error_code']) && null === $entry->getErrorCode()) {
|
||||||
|
$entry->setErrorCode($extra['error_code']);
|
||||||
|
++$totalUpdated;
|
||||||
|
}
|
||||||
|
++$totalProcessed;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->entityManager->flush();
|
||||||
|
$this->entityManager->clear();
|
||||||
|
|
||||||
|
$io->writeln(sprintf('Processed %d entries, %d updated so far', $totalProcessed, $totalUpdated));
|
||||||
|
}
|
||||||
|
|
||||||
|
$message = sprintf('Backfill complete. Processed %d entries, updated %d with error codes.', $totalProcessed, $totalUpdated);
|
||||||
|
$io->success($message);
|
||||||
|
|
||||||
|
return Command::SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,16 +4,27 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace App\Controller\Admin;
|
namespace App\Controller\Admin;
|
||||||
|
|
||||||
|
use App\Admin\Field\JsonDataField;
|
||||||
use App\Entity\LogEntry;
|
use App\Entity\LogEntry;
|
||||||
|
use App\Repository\LogEntryRepository;
|
||||||
|
use App\Service\XmlDumpService;
|
||||||
use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
|
use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
|
||||||
use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
|
use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
|
||||||
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
|
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
|
||||||
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
|
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
|
||||||
use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField;
|
use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField;
|
||||||
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
|
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
|
||||||
|
use League\Flysystem\FilesystemException;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
|
||||||
class LogEntryCrudController extends AbstractCrudController
|
class LogEntryCrudController extends AbstractCrudController
|
||||||
{
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly LogEntryRepository $logEntryRepository,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
public static function getEntityFqcn(): string
|
public static function getEntityFqcn(): string
|
||||||
{
|
{
|
||||||
return LogEntry::class;
|
return LogEntry::class;
|
||||||
@@ -22,7 +33,7 @@ class LogEntryCrudController extends AbstractCrudController
|
|||||||
public function configureActions(Actions $actions): Actions
|
public function configureActions(Actions $actions): Actions
|
||||||
{
|
{
|
||||||
$viewDumps = Action::new('viewDumps', 'XML Dumps', 'fa fa-file-code')
|
$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());
|
->displayIf(static fn (LogEntry $entity): bool => 'bpn' === $entity->getChannel());
|
||||||
|
|
||||||
return $actions
|
return $actions
|
||||||
@@ -42,18 +53,45 @@ class LogEntryCrudController extends AbstractCrudController
|
|||||||
return $crud
|
return $crud
|
||||||
->setEntityLabelInSingular('Logeintrag')
|
->setEntityLabelInSingular('Logeintrag')
|
||||||
->setEntityLabelInPlural('Logeinträge')
|
->setEntityLabelInPlural('Logeinträge')
|
||||||
->setDefaultSort(['createdAt' => 'DESC']);
|
->setDefaultSort(['createdAt' => 'DESC'])
|
||||||
|
->setSearchFields(['errorCode', 'message', 'channel', 'extra']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function configureFields(string $pageName): iterable
|
public function configureFields(string $pageName): iterable
|
||||||
{
|
{
|
||||||
return [
|
yield DateTimeField::new('createdAt', 'Zeitstempel');
|
||||||
DateTimeField::new('createdAt', 'Zeitstempel'),
|
yield TextField::new('errorCode', 'Fehlercode')
|
||||||
TextField::new('errorCode', 'Fehlercode'),
|
->formatValue(static fn (?string $value): string => $value ?? '-');
|
||||||
TextField::new('username', 'Benutzer'),
|
yield TextField::new('username', 'Benutzer');
|
||||||
TextField::new('message', 'Aktion'),
|
yield TextField::new('message', 'Aktion');
|
||||||
TextField::new('requestId', 'Request ID'),
|
yield TextField::new('requestId', 'Request ID');
|
||||||
TextField::new('uri', 'URI'),
|
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,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-2
@@ -8,6 +8,7 @@ use App\Repository\LogEntryRepository;
|
|||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
|
||||||
#[ORM\Entity(repositoryClass: LogEntryRepository::class)]
|
#[ORM\Entity(repositoryClass: LogEntryRepository::class)]
|
||||||
|
#[ORM\Table(indexes: [new ORM\Index(name: 'IDX_LOG_ENTRY_ERROR_CODE', columns: ['error_code'])])]
|
||||||
class LogEntry
|
class LogEntry
|
||||||
{
|
{
|
||||||
#[ORM\Id]
|
#[ORM\Id]
|
||||||
@@ -30,6 +31,9 @@ class LogEntry
|
|||||||
#[ORM\Column(type: 'datetime_immutable')]
|
#[ORM\Column(type: 'datetime_immutable')]
|
||||||
private \DateTimeImmutable $createdAt;
|
private \DateTimeImmutable $createdAt;
|
||||||
|
|
||||||
|
#[ORM\Column(type: 'string', length: 12, nullable: true)]
|
||||||
|
private ?string $errorCode = null;
|
||||||
|
|
||||||
public function __construct(string $channel, string $message)
|
public function __construct(string $channel, string $message)
|
||||||
{
|
{
|
||||||
$this->channel = $channel;
|
$this->channel = $channel;
|
||||||
@@ -112,9 +116,16 @@ class LogEntry
|
|||||||
return $this->getExtra()['request_id'] ?? '-';
|
return $this->getExtra()['request_id'] ?? '-';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getErrorCode(): string
|
public function getErrorCode(): ?string
|
||||||
{
|
{
|
||||||
return $this->getExtra()['error_code'] ?? '-';
|
return $this->errorCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setErrorCode(?string $errorCode): self
|
||||||
|
{
|
||||||
|
$this->errorCode = $errorCode;
|
||||||
|
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getUri(): string
|
public function getUri(): string
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ class DatabaseHandler extends AbstractProcessingHandler
|
|||||||
$logEntry
|
$logEntry
|
||||||
->setContext($record->context)
|
->setContext($record->context)
|
||||||
->setExtra($record->extra)
|
->setExtra($record->extra)
|
||||||
|
->setErrorCode($record->extra['error_code'] ?? null)
|
||||||
;
|
;
|
||||||
|
|
||||||
$this->entityManager->persist($logEntry);
|
$this->entityManager->persist($logEntry);
|
||||||
|
|||||||
@@ -27,4 +27,13 @@ class LogEntryRepository extends ServiceEntityRepository
|
|||||||
->getQuery()
|
->getQuery()
|
||||||
->execute();
|
->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function findWithErrorCodes(): array
|
||||||
|
{
|
||||||
|
return $this->createQueryBuilder('l')
|
||||||
|
->where('l.errorCode IS NOT NULL')
|
||||||
|
->orderBy('l.createdAt', 'DESC')
|
||||||
|
->getQuery()
|
||||||
|
->getResult();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th>Dateiname</th>
|
<th>Dateiname</th>
|
||||||
<th>Typ</th>
|
<th>Typ</th>
|
||||||
<th class="text-end">Dateigröße</th>
|
<th class="text-end">Dateigröße</th>
|
||||||
<th class="text-end">Aktion</th>
|
<th class="text-end">Aktion</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@@ -55,7 +55,7 @@
|
|||||||
<div class="content-panel-footer">
|
<div class="content-panel-footer">
|
||||||
<a href="{{ ea_url().setController('App\\Controller\\Admin\\LogEntryCrudController').setAction('index') }}"
|
<a href="{{ ea_url().setController('App\\Controller\\Admin\\LogEntryCrudController').setAction('index') }}"
|
||||||
class="btn btn-secondary">
|
class="btn btn-secondary">
|
||||||
<i class="fa fa-arrow-left"></i> Zurück zur Liste
|
<i class="fa fa-arrow-left"></i> Zurück zur Liste
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user