? 547902.patch
? includes/table.inc
Index: commands/core/watchdog.drush.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/drush/commands/core/watchdog.drush.inc,v
retrieving revision 1.7
diff -u -r1.7 watchdog.drush.inc
--- commands/core/watchdog.drush.inc	2 Mar 2010 02:18:56 -0000	1.7
+++ commands/core/watchdog.drush.inc	4 Mar 2010 00:12:00 -0000
@@ -33,6 +33,7 @@
       '--count' => 'The number of messages to show. Defaults to 10.',
       '--severity' => 'Restrict to messages of a given severity level.',
       '--type' => 'Restrict to messages of a given type.',
+      '--tail' => 'Continuously show new watchdog messages until interrupted.'
     ),
     'examples' => array(
       'watchdog-show' => 'Show a listing of most recent 10 messages.',
@@ -41,6 +42,7 @@
       'watchdog-show --count=46' => 'Show a listing of most recent 46 messages.',
       'watchdog-show --severity=notice' => 'Show a listing of most recent 10 messages with a severity of notice.',
       'watchdog-show --type=php' => 'Show a listing of most recent 10 messages of type php.',
+      'watchdog-show --tail' => 'Show a listing of most recent 10 messages and continue showing messages as they are registered in the watchdog.',
     ),
     'aliases' => array('wd-show', 'ws'),
   );
@@ -135,6 +137,7 @@
   $count = drush_get_option('count', 10);
   $type = drush_get_option('type');
   $severity = drush_get_option('severity');
+  $tail = drush_get_option('tail', FALSE);
 
   $where = core_watchdog_query($type, $severity, $filter);
   if ($where === FALSE) {
@@ -144,22 +147,51 @@
   if ($rsc === FALSE) {
     return drush_log(dt('Aborting.'));
   }
-  $table[] = array(dt('Id'), dt('Date'), dt('Severity'), dt('Type'), dt('Message'));
+  $header = array(dt('Id'), dt('Date'), dt('Severity'), dt('Type'), dt('Message'));
   while ($result = drush_db_fetch_object($rsc)) {
     $row = core_watchdog_format_result($result);
     $table[] = array($row->wid, $row->date, $row->severity, $row->type, $row->message);
   }
-  if (count($table) == 1) {
+  if (count($table) == 0) {
     return drush_log(dt('No log messages available.'), 'ok');
   }
   else {
     drush_log(dt('Most recent !count watchdog log messages:', array('!count' => $count)));
-    drush_print_table($table, TRUE);
+    if ($tail) {
+      $table = array_reverse($table);
+    }
+    array_unshift($table, $header);
+    $tbl = drush_print_table($table, TRUE);
+  }
+
+  if ($tail) {
+    $last = array_pop($table);
+    $last_wid = $last[0];
+    if ($where['where'] != '') {
+      $where['where'] .= ' AND ';
+    }
+    $where['where'] .= 'wid > :wid';
+    $tbl->_headers = NULL;
+    while (TRUE) {
+      $where['args'][':wid'] = $last_wid;
+      $table = array();
+      $tbl->_data = array();
+      $rsc = drush_db_select('watchdog', '*', $where['where'], $where['args'], NULL, NULL, 'wid', 'ASC');
+      while ($result = drush_db_fetch_object($rsc)) {
+        $row = core_watchdog_format_result($result);
+        $table[] = array($row->wid, $row->date, $row->severity, $row->type, $row->message);
+        $last_wid = $row->wid;
+      }
+      $tbl->addData($table);
+      print $tbl->_buildTable();
+      sleep(1);
+    }
+  }
+  else {
     print "\n";
   }
 }
 
-
 /**
  * Format a watchdog database row.
  *
Index: includes/drush.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/drush/includes/drush.inc,v
retrieving revision 1.94
diff -u -r1.94 drush.inc
--- includes/drush.inc	2 Mar 2010 03:41:45 -0000	1.94
+++ includes/drush.inc	4 Mar 2010 00:12:00 -0000
@@ -887,6 +887,7 @@
 
   $tbl->addData($newrows);
   print $tbl->getTable();
+  return $tbl;
 }
 
 /**
