14

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?

2 Answers 2

15
db_delete('watchdog')->execute();
1
  • 1
    db_truncate() is faster
    – Pere
    Mar 3, 2013 at 23:06
43

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
5
  • 1
    This should be the accepted answer! Sep 16, 2013 at 10:24
  • Can you trigger drush commands from inside a module?
    – akalata
    Nov 8, 2013 at 22:07
  • @akalata No, you can't.
    – mpdonadio
    Nov 8, 2013 at 22:44
  • 8
    It is an excellent answer but the question asks for a solution for running in a module. Jun 22, 2014 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 Jan 22, 2015 at 17:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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