function _drush_log_drupal_messages

8.0.x _drush_log_drupal_messages()
6.x _drush_log_drupal_messages()
7.x _drush_log_drupal_messages()
3.x _drush_log_drupal_messages()
4.x _drush_log_drupal_messages()
5.x _drush_log_drupal_messages()
master _drush_log_drupal_messages()

Turn drupal_set_message errors into drush_log errors

Related topics

6 calls to _drush_log_drupal_messages()
DrupalBoot::bootstrap_drupal_full in lib/Drush/Boot/DrupalBoot.php
Attempt to load the full Drupal system.
DrupalBoot::bootstrap_drupal_login in lib/Drush/Boot/DrupalBoot.php
Log into the bootstrapped Drupal site with a specific username or user id.
drush_command in includes/
Entry point for commands into the drush_invoke() API
drush_pm_enable_validate in commands/pm/
Validate callback. Determine the modules and themes that the user would like enabled.
drush_shutdown in includes/
Shutdown function for use while Drush and Drupal are bootstrapping and to return any registered errors.

... See full list


includes/, line 1400
The drush API implementation and helpers.


function _drush_log_drupal_messages() {
  if (function_exists('drupal_get_messages')) {

    $messages = drupal_get_messages(NULL, TRUE);

    if (array_key_exists('error', $messages)) {
      //Drupal message errors.
      foreach ((array) $messages['error'] as $error) {
        $error = strip_tags($error);
        $header = preg_match('/^warning: Cannot modify header information - headers already sent by /i', $error);
        $session = preg_match('/^warning: session_start\(\): Cannot send session /i', $error);
        if ($header || $session) {
          //These are special cases for an unavoidable warnings
          //that are generated by generating output before Drupal is bootstrapped.
          //or sending a session cookie (seems to affect d7 only?)
          //Simply ignore them.
        elseif (preg_match('/^warning:/i', $error)) {
          drush_log(preg_replace('/^warning: /i', '', $error), LogLevel::WARNING);
        elseif (preg_match('/^notice:/i', $error)) {
          drush_log(preg_replace('/^notice: /i', '', $error), LogLevel::NOTICE);
        elseif (preg_match('/^user warning:/i', $error)) {
          // This is a special case. PHP logs sql errors as 'User Warnings', not errors.
          drush_set_error('DRUSH_DRUPAL_ERROR_MESSAGE', preg_replace('/^user warning: /i', '', $error));
        else {
          drush_set_error('DRUSH_DRUPAL_ERROR_MESSAGE', $error);

    // Log non-error messages.
    foreach ($messages as $type => $items) {
      foreach ($items as $item) {
        drush_log(strip_tags($item), $type);