/**
  * Write the log to database
  *
  * @param mixed $level
  * @param string $message
  * @param array $context
  * @return bool Success
  */
 public function log($level, $message, array $context = [])
 {
     if ($this->config('type')) {
         $level = $this->config('type');
     }
     return $this->Logs->log($level, $message, $context);
 }
 /**
  * Setup
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     $this->Logs = TableRegistry::get('DatabaseLog.DatabaseLogs');
     if (!$this->Logs->find()->count()) {
         $this->Logs->log('warning', 'Foo Warning', ['x' => 'y']);
     }
 }
 /**
  * Tests the log write method
  *
  * @return void
  */
 public function testLogWriting()
 {
     $View = new View();
     $countBefore = $this->Logs->find()->count();
     $View->log('x');
     $View->log('warning', LOG_WARNING);
     Log::write(LOG_ERR, 'y');
     Log::write(LOG_INFO, 'z');
     $countAfter = $this->Logs->find()->count();
     $this->assertSame($countBefore + 8, $countAfter);
     // should be 4 (but for some reason everything is added twice
 }
 /**
  * Tests the removeDuplicates method
  *
  * @return void
  * @covers ::removeDuplicates
  */
 public function testRemoveDuplicates()
 {
     $data = ['type' => 'Foo', 'message' => 'some text'];
     $log = $this->Logs->newEntity($data);
     $res = $this->Logs->save($log);
     $this->assertTrue(!empty($res));
     $data = ['type' => 'Bar', 'message' => 'some more text'];
     $log = $this->Logs->newEntity($data);
     $res = $this->Logs->save($log);
     $this->assertTrue(!empty($res));
     $log = $this->Logs->newEntity($data);
     $res = $this->Logs->save($log);
     $this->assertTrue(!empty($res));
     $resBefore = $this->Logs->find()->count();
     $this->Logs->removeDuplicates();
     $resAfter = $this->Logs->find()->count();
     $this->assertSame($resBefore - 1, $resAfter);
 }