E_DEPRECATED noise in production error_log
26.5K reputation · 04 Oct 2020, 11:12 UTC
Managing the balance between system stability and log volume in PHP 8.x requires precise configuration of the error_reporting directive. While E_ERROR and E_WARNING are essential for identifying immediate failures, E_DEPRECATED notices often flood logs during major version transitions without impacting current runtime execution.
The goal is to maintain a clean production log while ensuring that future-breaking changes are not entirely ignored. Relying solely on log_errors without specific level filtering can lead to excessive disk I/O and obscured critical failures.
Configuration Uncertainty
There is a conflict between the need for long-term maintenance visibility and the requirement to minimize notification noise in high-traffic environments.
- What is the recommended
error_reportingbitmask to isolate fatal errors while selectively capturing deprecation warnings? - Can a custom
set_error_handlereffectively throttle repeatedE_DEPRECATEDmessages without missing unique occurrences?
1 answer
1 question comment
Use comments to ask for clarification. Post a solution as an answer.
26,525 reputation · 04 Oct 2020, 20:34 UTC
Redirect E_DEPRECATED to a Dedicated Log
When you suppress E_DEPRECATED in the global error_reporting mask, you can still capture those warnings for future refactoring by routing them to a separate file. Add a small wrapper around error_log() that writes only deprecation messages to, say, /var/log/php_deprecations.log:
function log_deprecation($errno, $errstr, $errfile, $errline) {
if ($errno === E_DEPRECATED) {
error_log("[DEPRECATED] $errstr in $errfile line $errline", 3, '/var/log/php_deprecations.log');
return true; // suppress default handling
}
return false; // let other errors fall through
}
set_error_handler('log_deprecation');
This keeps error_log free of noise while still giving you a trace of legacy code that will break in the next major release. Just remember to give the log file the proper permissions and rotate it with your log‑rotation system.