How to show messages starting with "Debug : " to an administrator only? I'm developing a lot of complex rules in D7 and for debugging reasons it is very handy to have different messages (the standard Drupal message) within the website. For this I use "showing a message on the site".

If a message of this starts with "Debug : " then I want it to only be displayed for the role of administrator. I do not want to add a condition to every message. That's is just to much.

How to achieve this?

Note: I wrote my first "Hello world" module last month, so I have a custom module in the site. I have to find the correct hook for this, so I looked into https://api.drupal.org/api/drupal/includes%21module.inc/group/hooks/7. But I cannot find a good hook for this.
Option 1: Use the Disable Messages module

Use the Disable Messages module for this. Here is a quote from its project page:


  Gives a site owner options to disable specific messages shown to end users. The core drupal message system as offered by drupal_set_message is an excellent way for modules to send out messages to the end users. However not all drupal site owners are keen to show all the messages sent out by drupal core and all modules to their users. This module gives site administrators a reasonably powerful way to filter out messages shown to the end users.


Some of its features are:


  
  Filter out messages that match a full text string exactly.
  Filter out messages that match a regular expression.
  Permissions to specifically hide all messages of a given type from any role.
  Disable all filtering for specific users.
  Disable all filtering for specific paths.
  Apply filtering only for specific paths.
  Debug system to get messages in the HTML without showing it to the end users.
  


Available for either Drupal 6 or Drupal 7 (and a DEV version for Drupal 8).

Option 2: Write your custom code

Use a variation of the approach as explained on Hook into and Preprocess Drupal Messages? Here is a quote from it:


  The following example hides all error/warning messages from anonymous users and user's who don't have the 'administer nodes' permission. You can easily add your own conditions to filter out which message types should be displayed to who.


function mytheme_status_messages ($display = NULL) {

  $output = '';
  foreach (drupal_get_messages($display) as $type =&gt; $messages) {

    // skip all error/warning messages for anonymous users
    if (!user_is_logged_in() &amp;&amp; ($type == "error" || $type == "warning")) { continue; }

    // skip error/warning messages for users who don't have the 'administer nodes' permission
    else if (!user_access('administer nodes') &amp;&amp; ($type == "error" || $type == "warning")) { continue; }

    ...