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 7.1, Zend 3.0, Symfony 3.2, Laravel 5.2, PHPUnit 5.6, Doctrine 2.6