8000 Apply code review suggestions · symfony/symfony@da2bfeb · GitHub
[go: up one dir, main page]

Skip to content

Commit da2bfeb

Browse files
author
Omer LAKRAA
committed
Apply code review suggestions
1 parent 0c99425 commit da2bfeb

File tree

5 files changed

+8
-11
lines changed

5 files changed

+8
-11
lines changed

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ CHANGELOG
88
* Derivate `kernel.secret` from the decryption secret when its env var is not defined
99
* Make the `config/` directory optional in `MicroKernelTrait`, add support for service arguments in the
1010
invokable Kernel class, and register `FrameworkBundle` by default when the `bundles.php` file is missing
11-
* Add exception.x.log_channel
11+
* Add a new logging channel for exceptions to provide better granularity and control over exception logging.
1212

1313
7.1
1414
---

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ public function load(array $configs, ContainerBuilder $container): void
386386
if (!isset($exception['log_channel'])) {
387387
continue;
388388
}
389-
$loggers[$exception['log_channel']] = new Reference(sprintf('monolog.logger.%s', $exception['log_channel']));
389+
$loggers[$exception['log_channel']] = new Reference(sprintf('monolog.logger.%s', $exception['log_channel']), ContainerInterface::NULL_ON_INVALID_REFERENCE);
390390
}
391391

392392
$exceptionListener

src/Symfony/Component/HttpKernel/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
CHANGELOG
22
=========
3+
34
7.2
45
---
56

67
* Remove `@internal` flag and add `@final` to `ServicesResetter`
7-
* Add log_channel in `ErrorListener`
8+
* Add a new logging channel for exceptions to provide better granularity and control over exception logging.
89

910
7.1
1011
---

src/Symfony/Component/HttpKernel/EventListener/ErrorListener.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,9 @@ public static function getSubscribedEvents(): array
165165
protected function logException(\Throwable $exception, string $message, ?string $logLevel = null, ?string $logChannel = null): void
166166
{
167167
$logLevel ??= $this->resolveLogLevel($exception);
168-
169168
$logChannel ??= $this->resolveLogChannel($exception);
170169

171-
$logger = $this->getLogger($logChannel);
172-
173-
if(null === $logger) {
170+
if(!$logger = $this->getLogger($logChannel)) {
174171
return;
175172
}
176173

@@ -267,8 +264,8 @@ private function getInheritedAttribute(string $class, string $attribute): ?objec
267264
return $attributeReflector?->newInstance();
268265
}
269266

270-
private function getLogger(?string $logChannel = null): ?LoggerInterface
267+
private function getLogger(?string $logChannel): ?LoggerInterface
271268
{
272-
return $this->loggers[$logChannel] ?? $this->logger;
269+
return $logChannel ? $this->loggers[$logChannel] ?? $this->logger : $this->logger;
273270
}
274271
}

src/Symfony/Component/HttpKernel/Tests/EventListener/ErrorListenerTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ public function testHandleWithLogLevelAttribute()
143143
$this->assertCount(1, $logger->getLogs('warning'));
144144
}
145145

146-
147146
public function testHandleWithLogChannel()
148147
{
149148
$request = new Request();
@@ -196,7 +195,7 @@ public function testHandleWithLoggerChannelNotUsed()
196195

197196
$this->assertEquals(new Response('foo', 401), $event->getResponse());
198197

199-
$this->assertEquals(0, $defaultLogger->countErrors());
198+
$this->assertSame(0, $defaultLogger->countErrors());
200199
$this->assertCount(0, $defaultLogger->getLogs('critical'));
201200
$this->assertCount(1, $defaultLogger->getLogs('warning'));
202201
$this->assertCount(0, $channelLoger->getLogs('warning'));

0 commit comments

Comments
 (0)
0