Skip to content

Commit

Permalink
Disable HTTP exceptions logs to errors and keep them in access
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierstoval authored and trasher committed Nov 14, 2024
1 parent 4b1be4a commit 8d69d1f
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Glpi/Log/LegacyGlobalLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

namespace Glpi\Log;

use Glpi\Exception\Http\HttpExceptionInterface;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;

Expand Down Expand Up @@ -91,6 +92,15 @@ public function debug(\Stringable|string $message, array $context = []): void

public function log($level, \Stringable|string $message, array $context = []): void
{
if (isset($context['exception']) && $context['exception'] instanceof HttpExceptionInterface) {
// Bypass \Symfony\Component\HttpKernel\EventListener\ErrorListener's logging system.
// Symfony is force-logging all exceptions, even the deliberately thrown HTTP exceptions.
// In GLPI, 4xx exception are not usually an "issue", and are logged in the "access" channel.
// However, Symfony logs them in the "error" channel.
// To keep most of Symfony's behavior in non-HTTP exceptions, we just remove the HttpExceptionInterface from it.
return;
}

$this->getLogger()->log($level, $message, $context);
}
}

0 comments on commit 8d69d1f

Please sign in to comment.