1. Go to this page and download the library: Download ecourty/logger-bundle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Ecourty\LoggerBundle\Service\Logger;
final class PlaceOrderHandler
{
public function __construct(
private readonly Logger $logger,
) {
}
public function handle(Order $order): void
{
$this->logger->info(OrderLogContext::Created, 'Order placed', [
'orderId' => $order->getId(),
]);
}
}
namespace App\Order\Enum;
enum OrderLogContext: string
{
case Created = 'OrderCreated';
case PaymentFailed = 'OrderPaymentFailed';
}
namespace App\Security\Logger;
use App\Security\User;
use Ecourty\LoggerBundle\Contract\LogParameterProcessorInterface;
final class UserLogParameterProcessor implements LogParameterProcessorInterface
{
public function supports(mixed $value): bool
{
return $value instanceof User;
}
public function process(mixed $value): mixed
{
return [
'id' => $value->getId(),
'email' => $value->getEmail(),
];
}
}