drupal_set_message('whatever', 'error') should be integrated with logging

Created on 29 June 2013, almost 12 years ago
Updated 22 April 2025, 3 days ago

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

<!--Uncomment the relevant rows for the issue. -->
✨ Feature request
Status

Postponed: needs info

Version

11.0 πŸ”₯

Component

base system

Created by

πŸ‡«πŸ‡·France fgm Paris, France

Live updates comments and jobs are added and updated live.
  • stale-issue-cleanup

    To track issues in the developing policy for closing stale issues, [Policy, no patch] closing older issues

Sign in to follow issues

Comments & Activities

Not all content is available!

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

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Thank you for sharing your idea for improving Drupal.

    We are working to decide if this proposal meets the Criteria for evaluating proposed changes. There hasn't been any discussion here for over 8 years which suggests that this has either been implemented or there is no community support. Your thoughts on this will allow a decision to be made.

    Since we need more information to move forward with this issue, the status is now Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.

    Thanks!

Production build 0.71.5 2024