-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[HttpKernel][ErrorHandler] Allow setting log level for exceptions wit…
…h attribute
- Loading branch information
Showing
4 changed files
with
138 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\ErrorHandler\Attribute; | ||
|
||
/** | ||
* @author Dejan Angelov <angelovdejan@protonmail.com> | ||
*/ | ||
#[\Attribute(\Attribute::TARGET_CLASS)] | ||
final class LogLevel | ||
{ | ||
public function __construct(public readonly string $level) | ||
{ | ||
if (!\defined(sprintf("\Psr\Log\LogLevel::%s", strtoupper($this->level)))) { | ||
throw new \InvalidArgumentException(sprintf('Invalid log level - "%s".', $this->level)); | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/Symfony/Component/ErrorHandler/Tests/Attribute/LogLevelTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\ErrorHandler\Tests\Attribute; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Psr\Log\LogLevel as PsrLogLevel; | ||
use Symfony\Component\ErrorHandler\Attribute\LogLevel; | ||
|
||
/** | ||
* @author Dejan Angelov <angelovdejan@protonmail.com> | ||
*/ | ||
class LogLevelTest extends TestCase | ||
{ | ||
public function testWithValidLogLevel() | ||
{ | ||
$logLevel = PsrLogLevel::NOTICE; | ||
|
||
$attribute = new LogLevel($logLevel); | ||
|
||
$this->assertSame($logLevel, $attribute->level); | ||
} | ||
|
||
public function testWithInvalidLogLevel() | ||
{ | ||
$this->expectException(\InvalidArgumentException::class); | ||
$this->expectExceptionMessage('Invalid log level - "invalid".'); | ||
|
||
new LogLevel('invalid'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters