chore: complete update
This commit is contained in:
28
src/Application/System/BootLogger.php
Normal file
28
src/Application/System/BootLogger.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Application\System;
|
||||
|
||||
use App\Framework\Core\Events\ApplicationBooted;
|
||||
use App\Framework\Core\Events\OnEvent;
|
||||
use App\Framework\Logging\DefaultLogger;
|
||||
|
||||
final readonly class BootLogger
|
||||
{
|
||||
public function __construct(
|
||||
private DefaultLogger $logger
|
||||
) {}
|
||||
|
||||
#[OnEvent]
|
||||
public function log(ApplicationBooted $event): void
|
||||
{
|
||||
#echo "[Boot] {$event->bootTime->format('H:i:s')} | Env: {$event->environment}\n";
|
||||
|
||||
$this->logger->info('Application booted', [
|
||||
'boot_time' => $event->bootTime->format('Y-m-d H:i:s.u'),
|
||||
'environment' => $event->environment,
|
||||
'memory_usage' => memory_get_usage(true),
|
||||
'peak_memory' => memory_get_peak_usage(true)
|
||||
]);
|
||||
}
|
||||
}
|
||||
24
src/Application/System/ErrorLogger.php
Normal file
24
src/Application/System/ErrorLogger.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Application\System;
|
||||
|
||||
use App\Framework\Core\Events\ErrorOccurred;
|
||||
use App\Framework\Core\Events\OnEvent;
|
||||
|
||||
final readonly class ErrorLogger
|
||||
{
|
||||
/**
|
||||
* Logger für aufgetretene Fehler
|
||||
*/
|
||||
#[OnEvent(priority: 10)]
|
||||
public function logError(ErrorOccurred $event): void
|
||||
{
|
||||
$time = $event->occurredAt->format('Y-m-d H:i:s');
|
||||
$requestId = $event->requestId ? "[Request: {$event->requestId}]" : '';
|
||||
$message = "[{$time}] ERROR {$requestId} {$event->context}: {$event->error->getMessage()}";
|
||||
|
||||
// In einer produktiven Umgebung würden wir hier in eine Datei oder einen Service loggen
|
||||
error_log($message);
|
||||
}
|
||||
}
|
||||
30
src/Application/System/UserRegistrationLogger.php
Normal file
30
src/Application/System/UserRegistrationLogger.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Application\System;
|
||||
|
||||
use App\Framework\Core\Events\OnEvent;
|
||||
use App\Framework\Core\Events\UserRegistered;
|
||||
|
||||
/**
|
||||
* Logger für Benutzerregistrierungen
|
||||
*/
|
||||
final readonly class UserRegistrationLogger
|
||||
{
|
||||
/**
|
||||
* Protokolliert die Registrierung eines neuen Benutzers
|
||||
*/
|
||||
#[OnEvent]
|
||||
public function logUserRegistration(UserRegistered $event): void
|
||||
{
|
||||
$message = sprintf(
|
||||
"[%s] Neuer Benutzer registriert: %s (%s)",
|
||||
$event->occurredAt->format('Y-m-d H:i:s'),
|
||||
$event->username,
|
||||
$event->email
|
||||
);
|
||||
|
||||
// In der Produktion würden wir in eine Datei oder einen Service loggen
|
||||
error_log($message);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user