Log And Rethrow Duplication (ARCH7166)
Esta página aún no está disponible en tu idioma.
Key php.logging.log-and-rethrow · Severity warning · Category logging
Logging an exception and rethrowing it in the same handler produces duplicate log entries, since it is logged again higher up the stack.
Incorrect
Section titled “Incorrect”<?phptry { $this->repository->save($entity);} catch (\PDOException $e) { $this->logger->error('Save failed', ['exception' => $e]); throw $e;}Correct
Section titled “Correct”<?phptry { $this->repository->save($entity);} catch (\PDOException $e) { throw new PersistenceException('Save failed', 0, $e);}Either log and swallow, or add context and rethrow - not both.