0

Can somebody explain how watchdog searching works? I can never get it to locate the log entries I'm looking for.

Let's say I have the following watchdog entries:

476722  10/Jun 10:31  notice    content  page: updated Protective Factors in Elementary School.
476723  10/Jun 10:31  notice    php      Notice: Undefined offset: 3 in _menu_translate() (line 777 of /var/www/html/domainnamehere/includes/menu.inc).
476724  10/Jun 10:40  notice    content  page: updated School/District Administrators.
476725  10/Jun 10:42  notice    content  page: updated Teachers.
476726  10/Jun 10:42  notice    php      Notice: Undefined offset: 3 in _menu_translate() (line 777 of /var/www/html/domainnamehere/includes/menu.inc).

All of following return "No log messages available":

drush wd-show "Undefined offset"
drush wd-show "%Undefined offset%"
drush wd-show "menu_translate"

If I want to find all of the "Undefined offset" watchdog entries, what Drush command do I have to run?

  • Your commands are valid, but you had initially used ws-show, which I assumed was a typo. Is there a chance that you were trying drush ws-show? – hw. Jun 10 '13 at 15:14
  • yes, 'ws-show' was a typo. – DesignGoggles Jun 10 '13 at 15:29
  • hmm..as an FYI, this seems to be the case with any PHP errors in the Watchdog logs. – Chapabu Jun 10 '13 at 15:52
  • Interesting. It does seems to work with other error types, even custom ones. – DesignGoggles Jun 10 '13 at 16:03
3

You could just pass the stdout from Drush as the stdin to grep.

Example:

drush wd-show | grep 'Undefined offset'

As a bonus - If you want the errors in a file, try the following:

drush wd-show | grep 'Undefined offset' > ~/Undefined-errors.txt

This'll put the errors into a text file in your home directory :-)

  • Not exactly what I had in mind but gets the job done. – hw. Jun 10 '13 at 15:31
  • The only caveat would be that you have to add the -count modifier. wd-show is only includes the last 10 entries. Also, I don't believe this would translate into wd-delete. The matching functionality is OOTB Watchdog functionality, the question is... why doesn't it work the way the documentation states? – DesignGoggles Jun 10 '13 at 15:34
  • If you want it to work with wd-delete something like the following would work: drush wd-show | awk '{print $1}' | xargs drush wd-delete. However, you are right and it should just work. I've tested the command with other errors from the watchdog logs and it works fine, but I don't have any sites quickly to hand that have any PHP errors in them. – Chapabu Jun 10 '13 at 15:41
  • Actually that last command won't work at all because of the Id line in the first column :( – Chapabu Jun 10 '13 at 15:42
  • @Chapabu answered the question correctly and succinctly even though I was hoping for a different response. :) – DesignGoggles Jun 10 '13 at 20:20
1

Actually I wrote this feature for drush. Didn't realize this problem untill now.

The explanation: the watchdog message is stored as a text with variables that are replaced by using the t() function. OTOH drush wd search functionality is based on a database query.

That's the output you get:

# drush wd-show --type=php

 ID  Date          Type      Severity  Message                                                                   
 95  20/Jun 22:28  php       notice    Notice: Undefined variable: output in mothership_item_list() (line 304 of 
 94  20/Jun 22:27  php       notice    Notice: Undefined variable: output in mothership_item_list() (line 304 of 
 93  20/Jun 22:26  php       notice    Notice: Undefined variable: output in mothership_item_list() (line 304 of 
 91  20/Jun 22:26  php       notice    Notice: Undefined variable: output in mothership_item_list() (line 304 of 
 89  20/Jun 22:26  php       notice    Notice: Undefined variable: output in mothership_item_list() (line 304 of 
 88  20/Jun 22:26  php       notice    Notice: Undefined variable: output in mothership_item_list() (line 304 of 
 87  20/Jun 22:26  php       notice    Notice: Undefined variable: output in mothership_item_list() (line 304 of 
 86  20/Jun 22:26  php       notice    Notice: Undefined variable: output in mothership_item_list() (line 304 of 
 85  20/Jun 22:26  php       notice    Notice: Undefined variable: output in mothership_item_list() (line 304 of 
 84  20/Jun 22:26  php       notice    Notice: Undefined variable: output in mothership_item_list() (line 304 of 

But that's the database content:

# drush sql-query "SELECT wid,message FROM watchdog WHERE type='php' LIMIT 10"

wid message
27  %type: !message in %function (line %line of %file).
59  %type: !message in %function (line %line of %file).
60  %type: !message in %function (line %line of %file).
61  %type: !message in %function (line %line of %file).
62  %type: !message in %function (line %line of %file).
63  %type: !message in %function (line %line of %file).
64  %type: !message in %function (line %line of %file).
66  %type: !message in %function (line %line of %file).
67  %type: !message in %function (line %line of %file).
68  %type: !message in %function (line %line of %file).

It doesn't seem there's an accurate fix for this. Drush could try to do its best on searching by filtering also by the 'variables' column of the watchdog table though.

  • Thank you very much for the explanation; this makes sense as to why I can't search for individual php errors. – DesignGoggles Jun 25 '13 at 16:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.