On most Drupal sites with a decent amount of traffic, individual log messages are less useful than information about how often they are occurring. We should add a command that shows the top N errors based on the given criteria. For example, it would be great to be able to see the 10 most common PHP warnings logged on a site.

Comments

deviantintegral’s picture

Status: Active » Needs work
StatusFileSize
new3.41 KB

Here is my work in progress. It prints out a table, but the table widths are currently broken. As well, there's no functionality to select what messages to summarize on.

deviantintegral’s picture

Status: Needs work » Needs review
StatusFileSize
new7.91 KB

Here's an updated patch courtesy of format-patch. I squashed all of my work into a single commit, but if anyone is interested in the history I can post that as well.

This patch adds a functional watchdog-summary command for both D6 and D7. As well, it refactors some of the severity and type checking.

$ drush wd-summary --help
Show a summary of watchdog messages. Arguments and options can be combined to configure which messages to show.

Examples:
 drush watchdog-summary                    Show the top 10 recorded watchdog messages. 
 drush watchdog-summary --severity=error   Show the top 10 recorded PHP errors.        
 --type=php                                                                            


Options:
 --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.           


Aliases: wd-summary
$ drush wd-summary 
 count  severity   type        message                                          
 3      info       system      <em class="placeholder">php</em> module          
                               installed.                                       
 2      info       system      <em class="placeholder">dblog</em> module        
                               installed.                                       
 2      info       system      <em class="placeholder">file</em> module         
                               installed.                                       
 2      info       system      <em class="placeholder">image</em> module        
                               installed.                                       
 2      info       system      <em class="placeholder">help</em> module         
                               installed.                                       
 2      info       system      <em class="placeholder">list</em> module         
                               installed.                                       
 2      info       system      <em class="placeholder">number</em> module       
                               installed.                                       
 2      info       system      <em class="placeholder">overlay</em> module      
                               installed.                                       
 2      info       system      <em class="placeholder">path</em> module         
                               installed.                                       
 2      info       system      <em class="placeholder">rdf</em> module          
                               installed.                                                                       

$ drush wd-summary --severity=notice
 count  severity   type        message                                          
 2      notice     user        Session opened for <em                           
                               class="placeholder">admin</em>.                  
 1      notice     actions     Action '<em class="placeholder">Publish          
                               comment</em>' added.                             
 1      notice     actions     Action '<em class="placeholder">Unpublish        
                               comment</em>' added.                             
 1      notice     actions     Action '<em class="placeholder">Save             
                               comment</em>' added.                             
 1      notice     actions     Action '<em class="placeholder">Publish          
                               content</em>' added.                             
 1      notice     actions     Action '<em class="placeholder">Unpublish        
                               content</em>' added.                             
 1      notice     actions     Action '<em class="placeholder">Make content     
                               sticky</em>' added.                              
 1      notice     actions     Action '<em class="placeholder">Make content     
                               unsticky</em>' added.                            
 1      notice     actions     Action '<em class="placeholder">Promote content  
                               to front page</em>' added.                       
 1      notice     actions     Action '<em class="placeholder">Remove content   
                               from front page</em>' added.                     
greg.1.anderson’s picture

Looks pretty useful. Maybe you could strip the html markup out of the messages?

deviantintegral’s picture

StatusFileSize
new8.85 KB

The attached wraps the message in trim(drush_html_to_text()).

greg.1.anderson’s picture

Status: Needs review » Needs work

I get some warnings:

Undefined variable: level watchdog.drush.inc:271                     [warning]
Undefined variable: level watchdog.drush.inc:274                     [warning]
Undefined variable: level watchdog.drush.inc:282                     [warning]

Seems to be a discrepancy between $severity (variable assigned) and $level ($variable used).

davidburns’s picture

Instead of stripping the HTML tags can we convert them to bold or color?

The simplest, and perhaps most useful ANSI escape sequence is bold text, \033[1m BOLD_TEXT_HERE \033[0m. The \033 represents an escape, the "[1" turns on the bold attribute, while the "[0" switches it off. The "m" terminates each term of the escape sequence.

greg.1.anderson’s picture

From drush_print_log:

  if (drush_get_context('DRUSH_NOCOLOR')) {
    $red = "[%s]";
    $yellow = "[%s]";
    $green = "[%s]";
  }
  else {
    $red = "\033[31;40m\033[1m[%s]\033[0m";
    $yellow = "\033[1;33;40m\033[1m[%s]\033[0m";
    $green = "\033[1;32;40m\033[1m[%s]\033[0m";
  }

Something similar could be done for bolded text.

However, I think this should be a separate issue. A motivated individual could modify drush_html_to_text() to do the right thing; patches welcome. (Extra points if the escape sequences from drush_print_log are factored out into a separate routine used wherever bold or colored text is needed.)

deviantintegral’s picture

greg.1.anderson’s picture

Status: Postponed » Needs work

I don't think it is necessary to block this issue on #1683026; could be done in either order, as desired.

deviantintegral’s picture

Status: Needs work » Needs review
StatusFileSize
new10.96 KB

The attached fixes the warnings above as well as fixes passing in --severity=0.

greg.1.anderson’s picture

Status: Needs review » Needs work

Still having some trouble with this.

Running without --severity or --type gives warnings about $level, and produces no output. Running with --severity=error gives no warnings, but summarizes all severity levels. Running with --severity=error and --type=php seems to produce the correct output.

greg.1.anderson’s picture

Version: » 8.x-6.x-dev
Status: Needs work » Closed (won't fix)
Issue tags: +Needs migration

This issue was marked closed (won't fix) because Drush has moved to Github.

If this feature is still desired, you may copy it to our Github project. For best results, create a Pull Request that has been updated for the master branch. Post a link here to the PR, and please also change the status of this issue to closed (duplicate).

Please ask support questions on Drupal Answers.