Aller au contenu

Structured Logging (ARCH7158)

Ce contenu n’est pas encore disponible dans votre langue.

Key php.logging.structured-logging · Severity warning · Category logging

Embedding variables via interpolation/concatenation in a log message hurts log aggregation. Use a parameterized message template instead.

<?php
$this->logger->info('User ' . $user->getId() . ' logged in from ' . $ip);
<?php
$this->logger->info('User {userId} logged in from {ip}', [
'userId' => $user->getId(),
'ip' => $ip,
]);

Pass values through placeholders in a parameterized context array instead of embedding them in the message.