13

I don't want to clear the watchdog log from the UI each time while debugging. It becomes time consuming and tedious.

Is there a Drupal function to clear the watchdog log inside a module?

12
db_delete('watchdog')->execute();
  • 1
    db_truncate() is faster – Pere Mar 3 '13 at 23:06
40

The best way to do this is via drush:

$ drush help watchdog-delete
Delete watchdog messages. Arguments or options must be provided to specify which messages to delete.

Examples:
 drush watchdog-delete all                 Delete all messages.
 drush watchdog-delete 64                  Delete messages with id 64.
 drush watchdog-delete "cron run           Delete messages containing the string "cron run succesful".
 succesful"
 drush watchdog-delete --severity=notice   Delete all messages with a severity of notice.
 drush watchdog-delete --type=cron         Delete all messages of type cron.


Arguments:
 severity                                  Delete messages of a given severity level.
 type                                      Delete messages of a given type.


Aliases: wd-del, wd-delete
  • 1
    This should be the accepted answer! – Matt Fletcher Sep 16 '13 at 10:24
  • Can you trigger drush commands from inside a module? – akalata Nov 8 '13 at 22:07
  • @akalata No, you can't. – mpdonadio Nov 8 '13 at 22:44
  • 7
    It is an excellent answer but the question asks for a solution for running in a module. – Francisco Luz Jun 22 '14 at 3:39
  • While this is highly useful, it does not actually answer the question appropriately. Although it appears at the time of the answer it did imply it was for debugging purposes, the question was edited shortly after this answer was posted. drupal.stackexchange.com/posts/18862/revisions – Elijah Lynn Jan 22 '15 at 17:11

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.