Problem/Motivation

In most cases, drupal_set_message() is just another channel for reporting information along with logging, and should be handled as such instead of requiring duplicate calls with inconsistent parameters.

Before anything else is done, we need to reach some consensus on whether this is desirable in the first instance. The motivation is to reduce the need for callers to send the same message to two channels (a logger and drupal_set_message()), but in many (most?) cases, the intended audience is different and it may not make sense to send the same message to both places.

Example 1: A form validation "error" because a user neglected to enter their zip code when creating a new account in is not necessarily an error that should be logged. Autorouting the drupal_set_message() call to the logger would be frivolous.

Example 2: In the event of a critical site error or database problem, it might make sense to send to the logger complete details (including the failing SQL statement and other details) while you would clearly not want this displayed to the end user (outside of a development environment).

On the other hand, a case might be made that UX developers and designers might in fact be interested in knowing which forms routinely result in validation errors (to spot fields or schemas that end users are regularly becoming confused about).

Proposed resolution

First, for this to happen in any automatic sense, the "error levels" or "categories" passed in the $type parameter to drupal_set_message() should be harmonized with the former watchdog() "error levels" (now provided for in Drupal\Core\Logger\RfcLoggerTrait). This element is essentially a duplicate of #1251960: harmonize severity/type in watchdog and drupal_set_message and should be addressed in that issue.

Second, it has been proposed that messages set via drupal_set_message() should also be sent to the system logger.

Remaining tasks

As noted above, it is not yet clear precisely how this should be implemented, if it should be implemented at all. Further discussion about the merits of this change is required.

Postponing to 8.1.x because this is a feature request, along with its related issue, will cause backward compatibility issues and potentially drastically changed behaviour.

User interface changes

Not yet determined.

API changes

Not yet entirely determined, but clearly #1251960: harmonize severity/type in watchdog and drupal_set_message would require a change to the drupal_set_message() function to harmonize the 'levels'.

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Feature, because this introduces new functionality (linking drupal_set_message() with logging).
Issue priority Normal and not-critical because it affects multiple systems but is not necessary for stabilization of core.
Prioritized changes This is not a prioritized change for the beta phase.
Disruption Potentially disruptive for core, contributed and custom modules because there would need to be some way of indicating which messages should be passed to both channels and which should not, and the related issue of harmonizing logging/status levels will require a BC break and widespread changes.

Comments

Crell’s picture

I'm not convinced of this. The error message I show to the user should be user-friendly, and help a user know what to do next. A legged error message should be developer/admin-friendly, and tell the developer/admin what to do to keep it from happening again. Variable dumps, for instance, make sense in the log message but not in the flash message. That many modules use the same string for both is not a feature; it's a lazy bug. :-)

marcingy’s picture

Category: bug » task

This can't be considered a bug this is a task at most.

Berdir’s picture

As a simple counter-example, there's absolutely no need to log things like validation errors as watchdog errors.

Not convinced either, don't think this makes sense.

fgm’s picture

As errors, obviously not. But a UX team might wish to get a log of validation errors channelled to them to work on usability of their screens, for example: it seems limiting to have core decide that such information will not be available by default, forcing teams to add extra code to handle such data acquisition needs.

Crell makes a good point, though: these functions target different audiences, and although most events may (or not) be of interest to both, the content of the data needed in both cases may often be subtly different : no exception stack traces for end users, and no sugary meaningless messages for devs.

Xano’s picture

As errors, obviously not. But a UX team might wish to get a log of validation errors channelled to them to work on usability of their screens,

Then we should add a debugging mode to watchdog that, when enabled, maps severities, runs messages through t() and displays them. This can probably even be done using a simple contributed module that implements hook_watchdog().

tibbsa’s picture

tibbsa’s picture

Version: 8.0.x-dev » 8.1.x-dev
Category: Task » Feature request
Issue summary: View changes
Status: Active » Postponed

Issue summary revamped and marked as postponed to 8.1.x as this amounts to a feature request and, in tandem with its related issue, will require API changes. None of this is important or critical to core at this stage.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.