Doctrine DBAL says Configuration::setSQLLogger() is deprecated
Configuration::setSQLLogger is deprecatedShort 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.
Fix it fast
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 -202Match what you see, then jump to its fix
What does the error look like?
Configuration::setSQLLogger is deprecatedConfiguration::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.phpConfirmed by github.com
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
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
Android gets HTML instead of JSON from a PHP API
org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject
The response body is not JSON.
2 causes, each with a fixBack 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 fixBack end
Apache returns 500 with Premature end of script headers
500 Internal Server Error
Apache ran your script, but the script printed no valid HTTP header before its output.
3 causes, each with a fixBack end
Apache returns 503 or 504 because PHP-FPM did not answer in time
Error dispatching request
Apache sent the request to PHP-FPM and gave up waiting.
3 causes, each with a fixBack end
AWS SDK for PHP cannot get credentials from the instance profile metadata server
Error retrieving credentials from the instance profile metadata server.
The SDK tries the EC2 instance metadata service when it has no valid credentials from anywhere earlier in its chain.
4 causes, each with a fixBack end
AWS SDK for PHP rejects requests: the signature is from the future
Signature not yet current: {date} is still later than {date}
AWS compares the timestamp in your signed request with its own clock.
2 causes, each with a fix