WithLogLevel.php 841 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\HttpKernel\Attribute;
  11. use Psr\Log\LogLevel;
  12. /**
  13. * Defines the log level applied to an exception.
  14. *
  15. * @author Dejan Angelov <angelovdejan@protonmail.com>
  16. */
  17. #[\Attribute(\Attribute::TARGET_CLASS)]
  18. final class WithLogLevel
  19. {
  20. /**
  21. * @param LogLevel::* $level The level to use to log the exception
  22. */
  23. public function __construct(public readonly string $level)
  24. {
  25. if (!\defined('Psr\Log\LogLevel::'.strtoupper($this->level))) {
  26. throw new \InvalidArgumentException(\sprintf('Invalid log level "%s".', $this->level));
  27. }
  28. }
  29. }