Add option to log deprecation errors to prepare for Drupal 9

Created on 7 January 2019, over 6 years ago
Updated 13 March 2023, about 2 years ago

Problem/Motivation

Dries had this IMHO great idea in https://twitter.com/Dries/status/1081582626560008192 I'd also love to see a "Log deprecated code" setting in /admin so you can also identify deprecated code without having to run tests. which could be a good way to turn on and let it run for a while to audit for problems. Proper tools to vet the results would still be important (dependencies will throw these errors, some errors should not be fixed too soon without core updates, etc), but we need some way to collect the data first.

User stories from #20:

  1. As a site owner, I want to see if my site can be upgraded to Drupal 9 (e.g. there should be no deprecations).
  2. As a developer, I want to see what deprecations I have to remove. Because I have to manage custom code, I'd like to know the module, file name and line number of the deprecated code.

Proposed resolution

Make it possible to collect E_USER_DEPRECATED errors in Drupal logs. Currently the standard for deprecated things is:

function drupal_get_messages($type = NULL, $clear_queue = TRUE) {
  @trigger_error('drupal_get_message() is deprecated in Drupal 8.5.0 and will be removed before Drupal 9.0.0. Use \\Drupal\\Core\\Messenger\\MessengerInterface::all() or \\Drupal\\Core\\Messenger\\MessengerInterface::messagesByType() instead. See https://www.drupal.org/node/2774931', E_USER_DEPRECATED);
  $messenger = \Drupal::messenger();
  // [...]

This *will* fire the Drupal error handler but due to the @ the error_reporting() result will be 0 and thus no error will be logged from _drupal_error_handler_real(). Should figure out a way to make it configurable to log these messages. Attached a tiny patch to test waters, but I think adding configurability in the error handler may be a recipe for disaster (endless loops of config errors leading to config errors, etc).

Remaining tasks

1. Figure out how to make this configurable.
2. Discuss log retention around these messages, these may generate a lot of logs fast, but at the same time aggregate results out of it would be *really* useful to prioritise work on a site.
3. In separate issue: discuss ways to improve making sense of this data, currently messages logged this way don't really stand out in logs and hard to filter for (they show up alongside other 'php' sourced errors and no further filter to filter to deprecated things or to aggregate them and see volumes):

User interface changes

Probably a new setting on /admin/config/development/logging to log deprecation errors. Maybe a new setting about log rotation for them.

API changes

None.

Data model changes

None.

Release notes snippet

TBD.

๐Ÿ“Œ Task
Status

Needs work

Version

10.1 โœจ

Component
Baseย  โ†’

Last updated about 12 hours ago

Created by

๐Ÿ‡ญ๐Ÿ‡บHungary Gรกbor Hojtsy Hungary

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024