Outdated doc #6941

Closed
opened 2026-01-22 15:41:53 +01:00 by admin · 12 comments
Owner

Originally created by @nimasdj on GitHub (Mar 3, 2022).

Bug Report

Documentation is outdated here: https://www.doctrine-project.org/projects/doctrine-orm/en/2.11/reference/advanced-configuration.html#sql-logger-optional as EchoSQLLogger doesn't exist anymore in latest version. which class should I use?

Originally created by @nimasdj on GitHub (Mar 3, 2022). ### Bug Report Documentation is outdated here: https://www.doctrine-project.org/projects/doctrine-orm/en/2.11/reference/advanced-configuration.html#sql-logger-optional as EchoSQLLogger doesn't exist anymore in latest version. which class should I use?
admin closed this issue 2026-01-22 15:41:53 +01:00
Author
Owner

@greg0ire commented on GitHub (Mar 3, 2022):

In fact, the SQLLogger interface itself is deprecated in favor of using a logging middleware

@greg0ire commented on GitHub (Mar 3, 2022): In fact, the `SQLLogger` interface itself is deprecated in favor of using [a logging middleware](https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/architecture.html#logging)
Author
Owner

@nimasdj commented on GitHub (Mar 3, 2022):

Could you please provide a sample code line how to use this middleware instead of EchoSQLLoger?

@nimasdj commented on GitHub (Mar 3, 2022): Could you please provide a sample code line how to use this middleware instead of EchoSQLLoger?
Author
Owner

@greg0ire commented on GitHub (Mar 3, 2022):

Sure!

use Doctrine\DBAL\Logging as LoggingMiddleware;

$logger = new MyLogger(); // use your favorite psr/log instance here
$this->_em->getConnection()->getConfiguration()->setMiddlewares([new LoggingMiddleware($logger)]);

EDIT: actually this is wrong, changing the middlewares at runtime has no effect.

@greg0ire commented on GitHub (Mar 3, 2022): Sure! ```php use Doctrine\DBAL\Logging as LoggingMiddleware; $logger = new MyLogger(); // use your favorite psr/log instance here $this->_em->getConnection()->getConfiguration()->setMiddlewares([new LoggingMiddleware($logger)]); ``` EDIT: actually this is wrong, changing the middlewares at runtime has no effect.
Author
Owner

@nimasdj commented on GitHub (Mar 4, 2022):

How can I use simple print instead of psr/log?

@nimasdj commented on GitHub (Mar 4, 2022): How can I use simple print instead of psr/log?
Author
Owner

@greg0ire commented on GitHub (Mar 4, 2022):

You can't, but you can extend https://github.com/php-fig/log/blob/master/src/AbstractLogger.php and implement log() with "simple print".

$this->_em->getConnection()->getConfiguration()->setMiddlewares([new LoggingMiddleware(new class extends AbstractLogger {
    public function log($level, $message, array $context = []): void
    {
        var_dump(func_get_args());
    }
})]);
@greg0ire commented on GitHub (Mar 4, 2022): You can't, but you can extend https://github.com/php-fig/log/blob/master/src/AbstractLogger.php and implement `log()` with "simple print". ```php $this->_em->getConnection()->getConfiguration()->setMiddlewares([new LoggingMiddleware(new class extends AbstractLogger { public function log($level, $message, array $context = []): void { var_dump(func_get_args()); } })]); ```
Author
Owner

@raziel057 commented on GitHub (Apr 25, 2022):

@greg0ire While I was trying to fix a deprecation by replacing the usage of SQLLogger by a Logging Middleware in a Symfony command, I encountered an issue related here https://github.com/symfony/symfony/issues/46158

Can you please advice on the way to proceed. Or maybe you should allow to replace a the logger in the connection decorator created by the middleware?

@raziel057 commented on GitHub (Apr 25, 2022): @greg0ire While I was trying to fix a deprecation by replacing the usage of SQLLogger by a Logging Middleware in a Symfony command, I encountered an issue related here https://github.com/symfony/symfony/issues/46158 Can you please advice on the way to proceed. Or maybe you should allow to replace a the logger in the connection decorator created by the middleware?
Author
Owner

@greg0ire commented on GitHub (Apr 25, 2022):

I think you should open a feature request on doctrine/dbal clearly explaining why you need the logger to be different in some contexts.

@greg0ire commented on GitHub (Apr 25, 2022): I think you should open a feature request on `doctrine/dbal` clearly explaining why you need the logger to be different in some contexts.
Author
Owner

@nimasdj commented on GitHub (Jul 4, 2022):

If I want to use https://github.com/php-fig/log/blob/master/src/AbstractLogger.php as you gave it in your sample code, do I need to have "use" line for this AbstractLogger.php? If yes, how should this "use" line be?

@nimasdj commented on GitHub (Jul 4, 2022): > If I want to use https://github.com/php-fig/log/blob/master/src/AbstractLogger.php as you gave it in your sample code, do I need to have "use" line for this AbstractLogger.php? If yes, how should this "use" line be?
Author
Owner

@greg0ire commented on GitHub (Jul 4, 2022):

@nimasdj use Psr\Log\AbstractLogger;

@greg0ire commented on GitHub (Jul 4, 2022): @nimasdj `use Psr\Log\AbstractLogger;`
Author
Owner

@nimasdj commented on GitHub (Aug 9, 2024):

Sure!

use Doctrine\DBAL\Logging as LoggingMiddleware;

$logger = new MyLogger(); // use your favorite psr/log instance here
$this->_em->getConnection()->getConfiguration()->setMiddlewares([new LoggingMiddleware($logger)]);

EDIT: actually this is wrong, changing the middlewares at runtime has no effect.

@greg0ire What is exactly wrong in your code above as you mentioned in "edit" area? How to improve the wrong thing you said?

@nimasdj commented on GitHub (Aug 9, 2024): > Sure! > > ``` > use Doctrine\DBAL\Logging as LoggingMiddleware; > > $logger = new MyLogger(); // use your favorite psr/log instance here > $this->_em->getConnection()->getConfiguration()->setMiddlewares([new LoggingMiddleware($logger)]); > ``` > > EDIT: actually this is wrong, changing the middlewares at runtime has no effect. @greg0ire What is exactly wrong in your code above as you mentioned in "edit" area? How to improve the wrong thing you said?
Author
Owner

@greg0ire commented on GitHub (Aug 9, 2024):

It's too late, and I'm not only talking about your answer, which is 2 years late. I mean calling setMiddlewares() here is too late, the connection has already been built.

@greg0ire commented on GitHub (Aug 9, 2024): It's too late, and I'm not only talking about your answer, which is 2 years late. I mean calling `setMiddlewares()` here is too late, the connection has already been built.
Author
Owner

@nimasdj commented on GitHub (Aug 9, 2024):

It's too late, and I'm not only talking about your answer, which is 2 years late. I mean calling setMiddlewares() here is too late, the connection has already been built.

@greg0ire So how the code should be to fix it?

@nimasdj commented on GitHub (Aug 9, 2024): > It's too late, and I'm not only talking about your answer, which is 2 years late. I mean calling `setMiddlewares()` here is too late, the connection has already been built. @greg0ire So how the code should be to fix it?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6941