2

I am in the process of upgrading an application from Symfony 5.4 to Symfony 6.0. Along the way, I had to upgrade some doctrine libraries.

We are currently using setSQLLogger(null) to avoid having SQL logging enabled. By using the newer version of Doctrine, I am getting a warning:

The Doctrine\DBAL\Configuration::setSQLLogger method is deprecated (Use {@see setMiddlewares()} and {@see \Doctrine\DBAL\Logging\Middleware} instead.).

I could not figure out how can I replace setSQLLogger(null) with setMiddlewares so I could disable the SQL logging.

Did anyone have this issue and managed to fix it?

Thanks.

2 Answers2

3

I replaced this code:

$em->getConnection()->getConfiguration()->setSQLLogger(null);

With:

$em->getConnection()->getConfiguration()->setMiddlewares([new \Doctrine\DBAL\Logging\Middleware(new \Psr\Log\NullLogger())]);

This puts the NullLogger as the only middleware.

Jorr.it
  • 1,222
  • 1
  • 14
  • 25
0

You should configure a middleware in order to accept the NullLogger, then use it along with setMiddlewares method.

So from symfony standpoint, you can do something like

# configuration.yaml // or whatever name you have
services:
  doctrine.logging.middleware.null: // or whatever name you prefer
    class: Doctrine\DBAL\Logging\Middleware
      autowire: false
      arguments:
        - #FQCN or service id of NullLogger

Then you can inject it where you were using setLogger and replace that method call with setMiddlewares.

I didn't tried it myself, as we're running on older version, but I'm pretty confident this should resolve your issue.

DonCallisto
  • 29,419
  • 9
  • 72
  • 100