I would like to tell watchdog not to write the "Cron run completed" to the log while leaving all other messages intact. How can I do this?



There is no special hook for this. The easiest way to fix this in Drupal 8 is overriding logger.dblog service.

According to the official documentation you need implement a class extending ServiceProviderBase and the alter() method as shown below.


namespace Drupal\example;

use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\DependencyInjection\ServiceProviderBase;

 * Modifies the logger.dblog service.
class ExampleServiceProvider extends ServiceProviderBase {

   * {@inheritdoc}
  public function alter(ContainerBuilder $container) {
    // Overrides logger.dblog service to exclude some unwanted log messages.


The logger itself is extremely simple.


namespace Drupal\example\Logger;

use Drupal\dblog\Logger\DbLog as BaseDbLog;

 * Logs events in the watchdog database table.
class DbLog extends BaseDbLog {

   * {@inheritdoc}
  public function log($level, $message, array $context = array()) {
    if ($message != t('Cron run completed.')) {
      parent::log($level, $message, $context);

  • Thanks. I am using Drupal 7 for the project where I want to suppress the messages... Any way to do that there? – Amir Simantov Dec 9 '16 at 11:59

For drupal 7 you could implement hook_watchdog() in a custom module to see the error messages but it will not allow you to change the messages logged into database. Read more about hook_watchdog here

For deleting specific messages perhaps you could implement hook_cron in your own module using something similar to what watchdog does when cleaning itself from excess messages as seen here but you have to adjust the code to find only specific messages to delete.

Perhaps viewing all log message except the ones you mentioned can be done with https://www.drupal.org/project/views_watchdog which allows you to create a view of dblog message and probably you can use views filtering to filter them out.

Or https://www.drupal.org/project/watchdog_filtering might be able to do the filtering for you

  • Thank you very much GiorgosK! So many ideas - I will check them all and comment here again. Amir – Amir Simantov May 1 '17 at 12:27
  • Hi, I have chosen the Views Watchdog module - thanks again. – Amir Simantov May 1 '17 at 22:51

Instead of trying to not write a specific log message, you can also ue the Views Watchdog module (to not include such messages when creating a list of log messages).

Some details about this module (from its project page):

... extends the Views module and allows to create customized lists (pages, blocks, feeds) of watchdog entries.


This module provides several fields, filter and sort criteria to build custom pages, blocks, and feeds.

It also provides the style Watchdog table to display watchdog entries as highlighted rows in a table.

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.