Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

Doctrine DBAL says Configuration::setSQLLogger() is deprecated

ErrorConfiguration::setSQLLogger is deprecated

Short answer

DBAL 3.2 deprecated SQLLogger, DebugStack, LoggerChain and Configuration::setSQLLogger(). The replacement is the Doctrine\DBAL\Logging\Middleware class, which wraps the driver and writes to a PSR-3 logger, passed in through Configuration::setMiddlewares(). There is no replacement for DebugStack.

  • Applies to doctrine/dbal 3.4 and later, PHP 8.3
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Find every place your code touches the old logging API. Frameworks and your own bootstrap code both show up in this search.

    grep -rnE "setSQLLogger|DebugStack|LoggerChain|SQLLogger" src/ config/ vendor/doctrine 2>/dev/null | head -20
  2. 2Match what you see, then jump to its fix

    1. 1The deprecation names a file in src/ or config/ rather than vendor/Your own code calls setSQLLogger()Fix
    2. 2The deprecation mentions DebugStack or LoggerChain, or your profiler code reads queries from a DebugStackYour code uses DebugStack or LoggerChainFix

What does the error look like?

  • Configuration::setSQLLogger is deprecated
  • Configuration::setSQLLogger is deprecated, use setMiddlewares() and Logging\Middleware instead

Cause 1 of 2

Your own code calls setSQLLogger()

1Check

The docblock of the method says to use setMiddlewares() and the Logging\Middleware class instead, and the method triggers a deprecation at run time.

grep -rn "setSQLLogger" src/ config/

2Fix

Remove the setSQLLogger() call and give the configuration a logging middleware that wraps a PSR-3 logger, for example a Monolog instance.

use Doctrine\DBAL\Configuration;
use Doctrine\DBAL\Logging\Middleware;

$configuration = new Configuration();
$configuration->setMiddlewares([new Middleware($psr3Logger)]);

3Verify

Run the code path that opens a connection. The deprecation is gone and queries reach your logger.

php -l src/Database.php

Confirmed by github.com

Did this fix it?

Cause 2 of 2

Your code uses DebugStack or LoggerChain

1Check

The upgrade notes for 3.2 list SQLLogger, DebugStack and LoggerChain as deprecated and say no replacement for DebugStack is provided.

grep -rnE "DebugStack|LoggerChain" src/

2Fix

Replace LoggerChain with your own logger setup, and replace DebugStack reads with the logging middleware writing to a logger or a handler that keeps records in memory in tests. If a framework toolbar needs the data, use its supported integration instead.

$configuration->setMiddlewares([new \Doctrine\DBAL\Logging\Middleware($psr3Logger)]);

3Verify

Search again; none of the old class names should be left.

grep -rnE "DebugStack|LoggerChain|setSQLLogger" src/ config/

Confirmed by github.com

Did this fix it?

How do I stop it coming back?

  • Run your tests with deprecations shown, so an upgrade of DBAL tells you what to change before it removes the API.
  • Send SQL logs to a PSR-3 logger so you can switch the destination without touching the connection code.
  • Read the UPGRADE.md file of doctrine/dbal when you change its major or minor version.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Back end

Apache returns 403 when a URL contains %3F

a request like /page%3Fname=test is refused while /page?name=test works

Recent Apache httpd blocks a rewrite when the request contains an encoded question mark (%3F) and the rewritten target has a literal ?.

2 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.