Logging In Loop (ARCH7164)
Ce contenu n’est pas encore disponible dans votre langue.
Key php.logging.logging-in-loop · Severity info · Category logging
Logging on every iteration inside a loop body can flood the log sink and degrade performance.
Incorrect
Section titled “Incorrect”<?phpforeach ($orders as $order) { $this->logger->info('Processing order', ['id' => $order->getId()]); $this->process($order);}Correct
Section titled “Correct”<?phpforeach ($orders as $order) { $this->process($order);}$this->logger->info('Processed orders', ['count' => count($orders)]);Write a summary record outside the loop instead of logging on every iteration.