Is it possible to write some code to intercept the process of adding Watchdog entries and filter them before adding to the log? Or is there a module that allows for watchdog filtering before adding to log? (I searched but nothing found) This would be useful if there are tons of well-known messages (like page not found from the same referrer or the same IP) that obfuscate the log.


Unfortunately hook_watchdog doesn't provide a return value which could block the insertion of the log entry in the database.

Note though that the responsible module for inserting the entry in the database is dblog. You could disable that and write your own implementation of it, although you'd have to replicate lots of functionality.

Another idea is to have a frequent cron job deleting the relevant log entries from the database table.

  • You mean the cron job as configured in Linux or in Drupal? If in Drupal, then how to specify what are the "Relevant log entries" ? I have a couple of regular expressions, where to put them? – camcam Oct 10 '12 at 9:29
  • I mean the cron mechanism of Drupal. Regarding the "relevant log entries" I meant the log entries which you consider that are worth deletion. I don't know which these are, you do. The implementation of dblog contains a cron function from which you could get some ideas. – cherouvim Oct 10 '12 at 9:31
  • 3
    From looking at the dblog_cron function, I'll try to write a custom function that does db_delete('watchdog') with conditions containing regular expressions that specify what to delete -and it should do it – camcam Oct 10 '12 at 9:53

Not sure if it's still relevant, but I've made a module where you can control logging per type per level: http://drupal.org/project/watchdog_filtering


I wrote a module that adds the needed D7 hook:


This module adds a hook_watchdog_alter. Used in DBLog Booster.


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.