Contributions API

Calling all Drupal developers!

Help us get this on the first page of Digg. DIGG NOW!

Modules in 6

drush_tools_watchdog_show

Definition

drush_tools_watchdog_show($limit = 10, $type = NULL)
contributions/drush/drush_tools/drush_tools.module, line 103

Description

Displays the most recent watchdog log messages (default: 10 messages).

Code

<?php
function drush_tools_watchdog_show($limit = 10, $type = NULL) {
  $severities = array(WATCHDOG_NOTICE => t('notice'), WATCHDOG_WARNING => t('warning'), WATCHDOG_ERROR => t('error'));

  $sql = 'SELECT w.*, u.name, u.uid FROM {watchdog} w INNER JOIN {users} u ON w.uid = u.uid';
  $sort = ' ORDER BY w.wid DESC';
  $result = (!empty($type) ?
    pager_query($sql . " WHERE w.type = '%s'" . $sort, (int)$limit, 0, NULL, $type) :
    pager_query($sql . $sort, (int)$limit));

  $rows = array();
  while ($watchdog = db_fetch_object($result)) {
    $rows[] = array(
      format_date($watchdog->timestamp, 'small'),
      str_pad($severities[$watchdog->severity], strlen(t('Severity'))),
      t($watchdog->type),
      _drush_tools_watchdog_format_message($watchdog->message),
      theme('username', $watchdog),
    );
  }

  if (count($rows) == 0) {
    drush_die(t('No log messages available.'));
  }
  drush_verbose(t('Last !count watchdog log messages:', array('!count' => $limit)));

  $rows[] = array(t('Date'), t('Severity'), t('Type'), t('Message'), t('User'));
  drush_print_table(array_reverse($rows), 2, true);
}
?>