Feat: Implement logging database handler
This commit is contained in:
@@ -69,8 +69,8 @@ class UserDataHandler
|
||||
$teamer->setCrmSelections($crmSelections);
|
||||
$user->setTeamer($teamer);
|
||||
$this->logger->info('Create teamer', [
|
||||
'id' => $teamer->getId(),
|
||||
'name' => $teamer->getFullName(),
|
||||
'teamer_id' => $teamer->getId(),
|
||||
'teamer_name' => (string) $teamer,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -78,8 +78,8 @@ class UserDataHandler
|
||||
$this->entityManager->flush();
|
||||
|
||||
$this->logger->info('Create user', [
|
||||
'id' => $user->getId(),
|
||||
'email' => $user->getEmail(),
|
||||
'user_id' => $user->getId(),
|
||||
'user_email' => $user->getEmail(),
|
||||
]);
|
||||
|
||||
return $user;
|
||||
@@ -97,18 +97,18 @@ class UserDataHandler
|
||||
if (true === $isTeamer) {
|
||||
$address = Address::fromApiResponse($profileResponse);
|
||||
$communication = Communication::fromApiResponse($profileResponse);
|
||||
$user
|
||||
->getTeamer()
|
||||
$teamer = $user->getTeamer();
|
||||
$teamer
|
||||
->setAddress($address)
|
||||
->setCommunication($communication)
|
||||
->setCrmSelections($crmSelections)
|
||||
;
|
||||
}
|
||||
|
||||
$this->logger->info('Update user', [
|
||||
'id' => $user->getId(),
|
||||
'email' => $user->getEmail(),
|
||||
]);
|
||||
$this->logger->info('Update teamer', [
|
||||
'teamer_id' => $teamer->getId(),
|
||||
'teamer_name' => (string) $teamer,
|
||||
]);
|
||||
}
|
||||
|
||||
$this->entityManager->flush();
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ class DeleteController extends AbstractController
|
||||
|
||||
$this->addFlash('success', 'Die Bewerbung wurde gelöscht');
|
||||
$this->logger->info('Delete application', [
|
||||
'application_id' => $application->getId(),
|
||||
'destination' => (string) $application->getAssignment()->getDestination(),
|
||||
'teamer' => (string) $application->getTeamer(),
|
||||
]);
|
||||
|
||||
|
||||
@@ -28,12 +28,10 @@ class DisposeController extends AbstractController
|
||||
|
||||
$this->entityManager->persist($disposition);
|
||||
$this->entityManager->remove($application);
|
||||
|
||||
$this->entityManager->flush();
|
||||
|
||||
$this->addFlash('success', 'Der Teamer wurde eingeteilt');
|
||||
$this->logger->info('Create disposition', [
|
||||
'application_id' => $application->getId(),
|
||||
'disposition_id' => $disposition->getId(),
|
||||
'teamer' => (string) $application->getTeamer(),
|
||||
]);
|
||||
|
||||
@@ -47,15 +47,15 @@ class DeleteController extends AbstractController
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$this->eventDispatcher->dispatch(new DispositionDeletedEvent($disposition), DispositionDeletedEvent::NAME);
|
||||
|
||||
$this->entityManager->remove($disposition);
|
||||
$this->entityManager->flush();
|
||||
|
||||
$this->addFlash('success', 'Die Einteilung wurde gelöscht');
|
||||
$this->logger->info('Delete disposition', [
|
||||
'disposition_id' => $disposition->getId(),
|
||||
'teamer' => (string) $disposition->getTeamer(),
|
||||
]);
|
||||
|
||||
$this->entityManager->remove($disposition);
|
||||
$this->entityManager->flush();
|
||||
|
||||
$response->setCloseAndRedirect($this->generateUrl('app_admin_assignment_detail', [
|
||||
'uuid' => $disposition->getAssignment()->getUuid(),
|
||||
]));
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Logging;
|
||||
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Monolog\Handler\AbstractProcessingHandler;
|
||||
use Monolog\LogRecord;
|
||||
|
||||
class DatabaseHandler extends AbstractProcessingHandler
|
||||
{
|
||||
public function __construct(private readonly Connection $connection)
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
protected function write(LogRecord $record): void
|
||||
{
|
||||
$this->connection->insert('log', [
|
||||
'level' => $record->level->getName(),
|
||||
'channel' => $record->channel,
|
||||
'message' => $record->message,
|
||||
'context' => json_encode($record->context),
|
||||
'extra' => json_encode($record->extra),
|
||||
'timestamp' => (new \DateTimeImmutable())->format('Y-m-d H:i:s'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Logging;
|
||||
|
||||
use App\Entity\User;
|
||||
use Monolog\LogRecord;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
|
||||
@@ -16,18 +17,20 @@ class InjectUserProcessor
|
||||
return $record;
|
||||
}
|
||||
|
||||
if ('cli' === php_sapi_name()) {
|
||||
/** @var User $user */
|
||||
$user = $this->security->getUser();
|
||||
|
||||
if (null === $user || 'cli' === php_sapi_name()) {
|
||||
$record->extra['user'] = [
|
||||
'id' => null,
|
||||
'username' => 'system',
|
||||
'role' => 'system',
|
||||
];
|
||||
return $record;
|
||||
} elseif (null === $user = $this->security->getUser()) {
|
||||
|
||||
return $record;
|
||||
}
|
||||
|
||||
$record['extra']['user'] = [
|
||||
$record->extra['user'] = [
|
||||
'id' => $user->getId(),
|
||||
'email' => $user->getEmail(),
|
||||
'roles' => $user->getRoles(),
|
||||
|
||||
Reference in New Issue
Block a user