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

  • 1
    db_truncate() is faster
    – Pere
    Commented Mar 3, 2013 at 23:06

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.

 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".
 drush watchdog-delete --severity=notice   Delete all messages with a severity of notice.
 drush watchdog-delete --type=cron         Delete all messages of type cron.

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

Your Answer

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

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