feat: extended logging

This commit is contained in:
Björn Fromme
2025-02-12 16:53:02 +01:00
parent c85fe2ee41
commit 1220398530
9 changed files with 92 additions and 24 deletions
+23 -10
View File
@@ -2,20 +2,26 @@ monolog:
channels: channels:
- deprecation # Deprecations are logged in the dedicated "deprecation" channel when it exists - deprecation # Deprecations are logged in the dedicated "deprecation" channel when it exists
- bpn - bpn
- core
when@dev: when@dev:
monolog: monolog:
handlers: handlers:
main:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.log"
level: debug
channels: ["!event"]
bpn: bpn:
type: stream type: stream
path: "%kernel.logs_dir%/%kernel.environment%.bpn.log" path: "%kernel.logs_dir%/%kernel.environment%.bpn.log"
level: debug level: debug
channels: ["bpn"] channels: ["bpn"]
core:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.core.log"
level: debug
channels: ["core"]
main:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.log"
level: debug
channels: ["!event"]
# uncomment to get logging in your browser # uncomment to get logging in your browser
# you may have to allow bigger header sizes in your Web server configuration # you may have to allow bigger header sizes in your Web server configuration
#firephp: #firephp:
@@ -46,17 +52,24 @@ when@test:
when@prod: when@prod:
monolog: monolog:
handlers: handlers:
bpn:
type: rotating_file
max_files: 7
path: "%kernel.logs_dir%/%kernel.environment%.bpn.log"
level: info
channels: ["bpn"]
core:
type: rotating_file
max_files: 7
path: "%kernel.logs_dir%/%kernel.environment%.core.log"
level: info
channels: ["core"]
main: main:
type: fingers_crossed type: fingers_crossed
action_level: error action_level: error
handler: nested handler: nested
excluded_http_codes: [404, 405] excluded_http_codes: [404, 405]
buffer_size: 50 # How many messages should be saved? Prevent memory leaks buffer_size: 50 # How many messages should be saved? Prevent memory leaks
bpn:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.bpn.log"
level: debug
channels: ["bpn"]
nested: nested:
type: stream type: stream
path: php://stderr path: php://stderr
+1
View File
@@ -12,6 +12,7 @@ services:
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc. autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
bind: bind:
$xmlPath: '%kernel.project_dir%/var/xmlexport' $xmlPath: '%kernel.project_dir%/var/xmlexport'
$logger: '@monolog.logger.core'
# makes classes in src/ available to be used as services # makes classes in src/ available to be used as services
# this creates a service per class whose id is the fully-qualified class name # this creates a service per class whose id is the fully-qualified class name
+6 -3
View File
@@ -34,9 +34,9 @@ class ApiClient
public function __construct( public function __construct(
private readonly SerializerInterface $serializer, private readonly SerializerInterface $serializer,
private readonly ApiResponseParser $responseParser, private readonly ApiResponseParser $responseParser,
private readonly LoggerInterface $logger, private readonly LoggerInterface $logger,
array $options array $options
) { ) {
$this->config = $this->resolveOptions($options); $this->config = $this->resolveOptions($options);
} }
@@ -296,6 +296,9 @@ class ApiClient
]) ])
; ;
$this->logger->info('Sending request to BPN API', [
'requestId' => $requestId,
]);
if (true === $this->config['debug']) { if (true === $this->config['debug']) {
$this->dumpXmlToFile('request', $requestId, $body); $this->dumpXmlToFile('request', $requestId, $body);
-1
View File
@@ -5,7 +5,6 @@ namespace App\BusProNet\Security;
use App\BusProNet\ApiClient; use App\BusProNet\ApiClient;
use App\BusProNet\Exception\ApiClientException; use App\BusProNet\Exception\ApiClientException;
use App\BusProNet\Model\CrmAttributes; use App\BusProNet\Model\CrmAttributes;
use App\BusProNet\Model\CrmAttributesResponse;
use App\BusProNet\Model\PersonalData; use App\BusProNet\Model\PersonalData;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\RedirectResponse;
@@ -4,6 +4,7 @@ namespace App\Controller\Booking;
use App\BusProNet\ApiClient; use App\BusProNet\ApiClient;
use App\BusProNet\Model\Notification; use App\BusProNet\Model\Notification;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Bundle\SecurityBundle\Security; use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
@@ -19,6 +20,7 @@ class DownloadController extends AbstractController
public function __construct( public function __construct(
private readonly ApiClient $apiClient, private readonly ApiClient $apiClient,
private readonly Security $security, private readonly Security $security,
private readonly LoggerInterface $logger,
) { ) {
} }
@@ -48,6 +50,12 @@ class DownloadController extends AbstractController
'confirmation' => 'Vorgangdruck', 'confirmation' => 'Vorgangdruck',
}; };
$this->logger->info('Initiated document download', [
'email' => $bpnUser->getEmail(),
'document_type' => $fileType,
'booking_id' => $id,
]);
$file = $this $file = $this
->apiClient ->apiClient
->getDocuments($bpnUser->getEmail(), $bpnUser->getPassword(), $id, $type) ->getDocuments($bpnUser->getEmail(), $bpnUser->getPassword(), $id, $type)
+20 -5
View File
@@ -8,6 +8,7 @@ use App\BusProNet\XmlLoader\TravelLoader;
use App\Form\BookingType; use App\Form\BookingType;
use App\Form\Model\BookingData; use App\Form\Model\BookingData;
use Psr\Cache\InvalidArgumentException; use Psr\Cache\InvalidArgumentException;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Bundle\SecurityBundle\Security; use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
@@ -20,11 +21,12 @@ use Symfony\Contracts\Cache\ItemInterface;
class EditController extends AbstractController class EditController extends AbstractController
{ {
public function __construct( public function __construct(
private readonly ApiClient $apiClient, private readonly ApiClient $apiClient,
private readonly TravelLoader $travelDataLoader, private readonly TravelLoader $travelDataLoader,
private readonly PickupLoader $pickupDataLoader, private readonly PickupLoader $pickupDataLoader,
private readonly CacheInterface $cache, private readonly CacheInterface $cache,
private readonly Security $security, private readonly Security $security,
private readonly LoggerInterface $logger,
) { ) {
} }
@@ -87,9 +89,17 @@ class EditController extends AbstractController
if ($form->isSubmitted() && $form->isValid()) { if ($form->isSubmitted() && $form->isValid()) {
$response = $this->apiClient->updateBooking($formData); $response = $this->apiClient->updateBooking($formData);
$this->logger->info('Initiated booking update', [
'email' => $bpnUser->getEmail(),
'booking_id' => $id,
]);
if (false === $response->isSuccessful()) { if (false === $response->isSuccessful()) {
$this->addFlash('error', $response->message); $this->addFlash('error', $response->message);
$this->logger->error('Error initiating booking update', [
'email' => $bpnUser->getEmail(),
'booking_id' => $id,
'message' => $response->message,
]);
} else { } else {
try { try {
$this->cache->delete($cacheKey); $this->cache->delete($cacheKey);
@@ -98,6 +108,11 @@ class EditController extends AbstractController
$this->addFlash('success', 'Buchung erfolgreich aktualisiert'); $this->addFlash('success', 'Buchung erfolgreich aktualisiert');
$this->logger->info('Booking update successful', [
'email' => $bpnUser->getEmail(),
'booking_id' => $id,
]);
return $this->redirectToRoute('app_booking_edit', ['id' => $id]); return $this->redirectToRoute('app_booking_edit', ['id' => $id]);
} }
} }
+13 -2
View File
@@ -5,6 +5,7 @@ namespace App\Controller;
use App\BusProNet\ApiClient; use App\BusProNet\ApiClient;
use App\BusProNet\Exception\ApiClientException; use App\BusProNet\Exception\ApiClientException;
use App\Form\PersonalDataType; use App\Form\PersonalDataType;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Bundle\SecurityBundle\Security; use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
@@ -14,8 +15,12 @@ use Symfony\Component\Security\Http\Attribute\IsGranted;
class PersonalDataController extends AbstractController class PersonalDataController extends AbstractController
{ {
public function __construct(private readonly ApiClient $apiClient, private readonly Security $security) public function __construct(
{} private readonly ApiClient $apiClient,
private readonly Security $security,
private readonly LoggerInterface $logger,
) {
}
#[Route('/personal-data', name: 'app_personal_data')] #[Route('/personal-data', name: 'app_personal_data')]
#[IsGranted('ROLE_USER')] #[IsGranted('ROLE_USER')]
@@ -41,6 +46,9 @@ class PersonalDataController extends AbstractController
try { try {
$this->apiClient->updatePersonalData($bpnUser->getEmail(), $bpnUser->getPassword(), $personalData); $this->apiClient->updatePersonalData($bpnUser->getEmail(), $bpnUser->getPassword(), $personalData);
$this->addFlash('success', 'Deine persönlichen Daten wurden aktualisiert'); $this->addFlash('success', 'Deine persönlichen Daten wurden aktualisiert');
$this->logger->info('Updated personal data', [
'email' => $bpnUser->getEmail(),
]);
} catch (ApiClientException $e) { } catch (ApiClientException $e) {
$this->addFlash('error', $e->getMessage()); $this->addFlash('error', $e->getMessage());
} }
@@ -74,6 +82,9 @@ class PersonalDataController extends AbstractController
try { try {
$this->apiClient->updateNewsletterRegistration($bpnUser->getEmail(), $bpnUser->getPassword(), $personalData); $this->apiClient->updateNewsletterRegistration($bpnUser->getEmail(), $bpnUser->getPassword(), $personalData);
$this->addFlash('success', 'Deine Anmeldung zum Newsletter wurde aktualisiert'); $this->addFlash('success', 'Deine Anmeldung zum Newsletter wurde aktualisiert');
$this->logger->info('Updated newsletter registration', [
'email' => $bpnUser->getEmail(),
]);
} catch (ApiClientException $e) { } catch (ApiClientException $e) {
$this->addFlash('error', $e->getMessage()); $this->addFlash('error', $e->getMessage());
} }
+12 -2
View File
@@ -6,6 +6,7 @@ use App\BusProNet\ApiClient;
use App\BusProNet\Exception\ApiClientException; use App\BusProNet\Exception\ApiClientException;
use App\Form\Model\RegistrationData; use App\Form\Model\RegistrationData;
use App\Form\RegistrationType; use App\Form\RegistrationType;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
@@ -14,8 +15,10 @@ use Symfony\Component\Security\Http\Attribute\IsGranted;
class RegistrationController extends AbstractController class RegistrationController extends AbstractController
{ {
public function __construct(private readonly ApiClient $apiClient) public function __construct(
{ private readonly ApiClient $apiClient,
private readonly LoggerInterface $logger,
) {
} }
#[Route('/registration', name: 'app_registration')] #[Route('/registration', name: 'app_registration')]
@@ -36,8 +39,15 @@ class RegistrationController extends AbstractController
} else { } else {
$this->addFlash('error', 'Möglicherweise bist du bereits registriert. Bitte setze dein Passwort zurück.'); $this->addFlash('error', 'Möglicherweise bist du bereits registriert. Bitte setze dein Passwort zurück.');
} }
$this->logger->info('Initiated registration', [
'email' => $registrationData->email,
]);
} catch (ApiClientException $e) { } catch (ApiClientException $e) {
$this->addFlash('error', $e->getMessage()); $this->addFlash('error', $e->getMessage());
$this->logger->error('Error initiating registration', [
'email' => $registrationData->email,
'error' => $e->getMessage(),
]);
} }
return $this->redirectToRoute('app_login'); return $this->redirectToRoute('app_login');
+9 -1
View File
@@ -4,6 +4,7 @@ namespace App\Controller;
use App\BusProNet\ApiClient; use App\BusProNet\ApiClient;
use App\BusProNet\Exception\ApiClientException; use App\BusProNet\Exception\ApiClientException;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\Extension\Core\Type\EmailType; use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
@@ -15,7 +16,7 @@ use Symfony\Component\Validator\Constraints\NotBlank;
class ResetPasswordController extends AbstractController class ResetPasswordController extends AbstractController
{ {
public function __construct(private readonly ApiClient $apiClient) public function __construct(private readonly ApiClient $apiClient, private readonly LoggerInterface $logger)
{ {
} }
@@ -47,8 +48,15 @@ class ResetPasswordController extends AbstractController
try { try {
$this->apiClient->resetPassword($form->get('email')->getData()); $this->apiClient->resetPassword($form->get('email')->getData());
$this->addFlash('success', 'Du erhältst in Kürze eine E-Mail mit einem Link zum (Zurück)setzen deines Passworts.'); $this->addFlash('success', 'Du erhältst in Kürze eine E-Mail mit einem Link zum (Zurück)setzen deines Passworts.');
$this->logger->info('Initiated password reset', [
'email' => $form->get('email')->getData(),
]);
} catch (ApiClientException $e) { } catch (ApiClientException $e) {
$this->addFlash('error', $e->getMessage()); $this->addFlash('error', $e->getMessage());
$this->logger->error('Error initiating password reset', [
'email' => $form->get('email')->getData(),
'error' => $e->getMessage(),
]);
} }
return $this->redirectToRoute('app_login'); return $this->redirectToRoute('app_login');