diff --git a/spec/Handler/Writer/DbSpec.php b/spec/Handler/Writer/DbSpec.php index f0b9e2f4..13ed9e60 100644 --- a/spec/Handler/Writer/DbSpec.php +++ b/spec/Handler/Writer/DbSpec.php @@ -86,7 +86,7 @@ allow($resultSet)->toReceive('current')->andReturn(null); allow(TableGateway::class)->toReceive('selectWith')->with($select)->andReturn($resultSet); - $actual = $this->writerHandler->isExists('file', 1, 'Undefined offset: 1', 'http://serverUrl/uri'); + $actual = $this->writerHandler->isExists('file', 1, 'Undefined offset: 1', 'http://serverUrl/uri', 'E_NOTICE'); expect($actual)->toBe(false); }); @@ -117,7 +117,7 @@ ); allow(TableGateway::class)->toReceive('selectWith')->with($select)->andReturn($resultSet); - $actual = $this->writerHandler->isExists('file', 1, 'Undefined offset: 1', 'http://serverUrl/uri'); + $actual = $this->writerHandler->isExists('file', 1, 'Undefined offset: 1', 'http://serverUrl/uri', 'E_NOTICE'); expect($actual)->toBe(false); }); @@ -143,7 +143,7 @@ ); allow(TableGateway::class)->toReceive('selectWith')->with($select)->andReturn($resultSet); - $actual = $this->writerHandler->isExists('file', 1, 'Undefined offset: 1', 'http://serverUrl/uri'); + $actual = $this->writerHandler->isExists('file', 1, 'Undefined offset: 1', 'http://serverUrl/uri', 'E_NOTICE'); expect($actual)->toBe(true); }); diff --git a/src/Handler/Logging.php b/src/Handler/Logging.php index 75745b09..409637b1 100644 --- a/src/Handler/Logging.php +++ b/src/Handler/Logging.php @@ -122,19 +122,20 @@ public function setServerRequestandRequestUri(ServerRequestInterface $request) * @param int $errorLine * @param string $errorMessage * @param string $url + * @param string $errorType * * @throws RuntimeException when cannot connect to DB in the first place * * @return bool */ - private function isExists($errorFile, $errorLine, $errorMessage, $url) + private function isExists($errorFile, $errorLine, $errorMessage, $url, $errorType) { $writers = $this->logger->getWriters()->toArray(); foreach ($writers as $writer) { if ($writer instanceof Db) { try { $handlerWriterDb = new Writer\Db($writer, $this->configLoggingSettings, $this->logWritersConfig); - if ($handlerWriterDb->isExists($errorFile, $errorLine, $errorMessage, $url)) { + if ($handlerWriterDb->isExists($errorFile, $errorLine, $errorMessage, $url, $errorType)) { return true; } break; @@ -288,7 +289,8 @@ public function handleErrorException($e) $collectedExceptionData['errorFile'], $collectedExceptionData['errorLine'], $collectedExceptionData['errorMessage'], - $this->serverUrl.$this->requestUri + $this->serverUrl.$this->requestUri, + $collectedExceptionData['errorType'] ) ) { return; diff --git a/src/Handler/Writer/Db.php b/src/Handler/Writer/Db.php index b8a602b1..fc10d1ed 100644 --- a/src/Handler/Writer/Db.php +++ b/src/Handler/Writer/Db.php @@ -44,10 +44,11 @@ public function __construct( * @param int $errorLine * @param string $errorMessage * @param string $errorUrl + * @param string $errorType * * @return bool */ - public function isExists($errorFile, $errorLine, $errorMessage, $errorUrl) + public function isExists($errorFile, $errorLine, $errorMessage, $errorUrl, $errorType) { // db definition $reflectionProperty = new ReflectionProperty($this->dbWriter, 'db'); @@ -60,20 +61,22 @@ public function isExists($errorFile, $errorLine, $errorMessage, $errorUrl) $table = $writerConfig['options']['table']; // columns definition - $timestamp = $writerConfig['options']['column']['timestamp']; - $message = $writerConfig['options']['column']['message']; - $file = $writerConfig['options']['column']['extra']['file']; - $line = $writerConfig['options']['column']['extra']['line']; - $url = $writerConfig['options']['column']['extra']['url']; + $timestamp = $writerConfig['options']['column']['timestamp']; + $message = $writerConfig['options']['column']['message']; + $file = $writerConfig['options']['column']['extra']['file']; + $line = $writerConfig['options']['column']['extra']['line']; + $url = $writerConfig['options']['column']['extra']['url']; + $error_type = $writerConfig['options']['column']['extra']['error_type']; $tableGateway = new TableGateway($table, $db, null, new ResultSet()); $select = $tableGateway->getSql()->select(); $select->columns([$timestamp]); $select->where([ - $message => $errorMessage, - $line => $errorLine, - $url => $errorUrl, - $file => $errorFile, + $message => $errorMessage, + $line => $errorLine, + $url => $errorUrl, + $file => $errorFile, + $error_type => $errorType, ]); $select->order($timestamp.' DESC'); $select->limit(1);