From f6ea2f768ddec396c5bc05434fcaa4b4a587ef41 Mon Sep 17 00:00:00 2001 From: Dave Long <dave@longwaveconsulting.com> Date: Wed, 15 Nov 2023 16:46:50 +0000 Subject: [PATCH] Issue #3377310 by catch, joelpittet, mark_fullmer, smustgrave, TrevorBradley, bkosborne, MWaters, cilefen, capellic: 400 exceptions result from requests for old asset paths which are missing the "theme" query string, possibly from cached pages (cherry picked from commit 96695551d4ddc57986b86db4a381af83208b02a3) --- .../ExceptionLoggingSubscriber.php | 2 +- .../ExceptionLoggingSubscriberTest.php | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/core/lib/Drupal/Core/EventSubscriber/ExceptionLoggingSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/ExceptionLoggingSubscriber.php index 8adc67a6c969..31b45d5e58aa 100644 --- a/core/lib/Drupal/Core/EventSubscriber/ExceptionLoggingSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/ExceptionLoggingSubscriber.php @@ -88,7 +88,7 @@ public function onClientError(ExceptionEvent $event) { 'status_code' => $exception->getStatusCode(), ]; $this->logger->get('client error') - ->log($error['severity_level'], Error::DEFAULT_ERROR_MESSAGE, $error); + ->warning(Error::DEFAULT_ERROR_MESSAGE, $error); } /** diff --git a/core/tests/Drupal/KernelTests/Core/EventSubscriber/ExceptionLoggingSubscriberTest.php b/core/tests/Drupal/KernelTests/Core/EventSubscriber/ExceptionLoggingSubscriberTest.php index b15ecff3f0fe..9bd4d5795056 100644 --- a/core/tests/Drupal/KernelTests/Core/EventSubscriber/ExceptionLoggingSubscriberTest.php +++ b/core/tests/Drupal/KernelTests/Core/EventSubscriber/ExceptionLoggingSubscriberTest.php @@ -3,6 +3,7 @@ namespace Drupal\KernelTests\Core\EventSubscriber; use Drupal\Core\DependencyInjection\ContainerBuilder; +use Drupal\Core\Logger\RfcLogLevel; use Drupal\KernelTests\KernelTestBase; use Symfony\Component\ErrorHandler\BufferingLogger; use Symfony\Component\HttpFoundation\Request; @@ -47,6 +48,18 @@ public function testExceptionLogging() { 503 => 'php', ]; + $level_map = [ + 400 => RfcLogLevel::WARNING, + 401 => RfcLogLevel::WARNING, + 403 => RfcLogLevel::WARNING, + 404 => RfcLogLevel::WARNING, + 405 => RfcLogLevel::WARNING, + 408 => RfcLogLevel::WARNING, + 501 => RfcLogLevel::ERROR, + 502 => RfcLogLevel::ERROR, + 503 => RfcLogLevel::ERROR, + ]; + // Ensure that noting is logged. $this->assertEmpty($this->container->get($this->testLogServiceName)->cleanLogs()); @@ -60,11 +73,12 @@ public function testExceptionLogging() { ini_set('error_log', $error_log); $expected_channels = array_values($channel_map); + $expected_levels = array_values($level_map); $logs = $this->container->get($this->testLogServiceName)->cleanLogs(); foreach ($expected_channels as $key => $expected_channel) { - $log_message = $logs[$key][2]['channel']; - $this->assertEquals($expected_channel, $log_message); + $this->assertEquals($expected_channel, $logs[$key][2]['channel']); + $this->assertEquals($expected_levels[$key], $logs[$key][0]); } } -- GitLab