CleanerWatchdogController.php in Cleaner 8        
                          
                  
                        
  
  
  
  
  
File
  src/Controller/CleanerWatchdogController.php
  
    View source  
  <?php
namespace Drupal\cleaner\Controller;
use Psr\Log\LogLevel;
class CleanerWatchdogController implements CleanerControllersInterface {
  
  public static $configName = 'cleaner_empty_watchdog';
  
  protected static $logLevel;
  
  protected static $logMessage;
  
  public function execute() {
    if (\Drupal::config(CLEANER_SETTINGS)
      ->get(self::$configName)) {
      if (self::cleanWatchdog()) {
        static::$logLevel = LogLevel::INFO;
        static::$logMessage = 'Watchdog logs has been successfully cleared.';
      }
      else {
        static::$logLevel = LogLevel::ERROR;
        static::$logMessage = 'Something going wrong - watchdog logs can\'t be cleared.';
      }
      \Drupal::service('cleaner_logger')
        ->log(static::$logLevel, static::$logMessage);
    }
  }
  
  private static function cleanWatchdog() {
    if (!\Drupal::database()
      ->schema()
      ->tableExists('watchdog')) {
      return FALSE;
    }
    return (bool) \Drupal::database()
      ->query('TRUNCATE {watchdog}')
      ->execute();
  }
}