You are here

function _drush_acquia_purge_ap_diagnosis_log in Acquia Purge 7

Log the given test.

Parameters

array $test: Associative array with the following elements:

  • title: The name of the requirement.
  • value: The current value (e.g., version, time, level, etc).
  • description: The description of the requirement/status.
  • severity: ACQUIA_PURGE_SEVLEVEL_INFO, _OK, _WARNING, _ERROR.

int $longest: The longest test name, used to calculate formatting padding.

1 call to _drush_acquia_purge_ap_diagnosis_log()
drush_acquia_purge_ap_diagnosis in ./acquia_purge.drush.inc
Perform a series of diagnostic self-tests.

File

./acquia_purge.drush.inc, line 135
Drush integration providing common maintenance tasks.

Code

function _drush_acquia_purge_ap_diagnosis_log(array $test, $longest) {

  // When running in backend mode, log messages aren't printed and forwarded.
  if (drush_get_context('DRUSH_BACKEND')) {
    $message = sprintf('%s: %s', $test['name'], $test['value_plain']);
    return drush_log($message, $test['drush_type']);
  }

  // When not running in backend mode, prepare for fancier output.
  $type = sprintf(' [%s]', $test['drush_type']);
  $pad_maxlength = 11;
  $colors = array(
    'info' => '%s',
    'error' => '%s',
    'warning' => '%s',
    'ok' => '%s',
  );

  // In color mode, setup ASCII color codes borrowed from _drush_print_log().
  if (!drush_get_context('DRUSH_NOCOLOR')) {
    $colors['error'] = "\33[31;40m\33[1m%s\33[0m";
    $colors['warning'] = "\33[1;33;40m\33[1m%s\33[0m";
    $colors['ok'] = "\33[1;32;40m\33[1m%s\33[0m";
  }

  // Print the test name and value.
  printf(sprintf($colors[$test['drush_type']], "%s%s%s%s%s\n"), $type, str_repeat(' ', $pad_maxlength - strlen($type)), drupal_strtoupper($test['name']), str_repeat(' ', $longest - strlen($test['name'])), $test['value_plain']);

  // Print descriptions for warnings and errors.
  if ($test['severity'] >= ACQUIA_PURGE_SEVLEVEL_WARNING) {
    $pad = str_repeat(' ', $pad_maxlength);
    printf(sprintf($colors[$test['drush_type']], "\n%s%s\n\n"), $pad, wordwrap($test['description_plain'], 2 * $longest, "\n{$pad}"));
  }
}