Adding logger for SQL queries into doctrine entity manager

Code
<?php

use PHPSnippets\Db\Entity\Test;
use 
Doctrine\DBAL\Logging\DebugStack;

$logger = new DebugStack();
$entityManager->getConnection()
    ->
getConfiguration()
    ->
setSQLLogger($logger);

$entity $entityManager->find(Test::CLASS, 2);

$current $logger->queries[$logger->currentQuery];
echo 
sprintf(
    
'<b>query:</b> %s, <b>params:</b> [%s]'
    
$current['sql'],
    
implode($current['params'])
);
Result
query: SELECT t0.id AS id_1, t0.name AS name_2, t0.creation_date AS creation_date_3 FROM test t0 WHERE t0.id = ?, params: [2]
Used Versions
PHP 8.2, Laminas MVC 3.2, Symfony 5.2, Laravel 8.28, PHPUnit 9.5, Doctrine ORM 2.8