NullHandler.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php declare(strict_types=1);
  2. /*
  3. * This file is part of the Monolog package.
  4. *
  5. * (c) Jordi Boggiano <j.boggiano@seld.be>
  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 Monolog\Handler;
  11. use Monolog\Level;
  12. use Psr\Log\LogLevel;
  13. use Monolog\Logger;
  14. use Monolog\LogRecord;
  15. /**
  16. * Blackhole
  17. *
  18. * Any record it can handle will be thrown away. This can be used
  19. * to put on top of an existing stack to override it temporarily.
  20. *
  21. * @author Jordi Boggiano <j.boggiano@seld.be>
  22. */
  23. class NullHandler extends Handler
  24. {
  25. private Level $level;
  26. /**
  27. * @param string|int|Level $level The minimum logging level at which this handler will be triggered
  28. *
  29. * @phpstan-param value-of<Level::VALUES>|value-of<Level::NAMES>|Level|LogLevel::* $level
  30. */
  31. public function __construct(string|int|Level $level = Level::Debug)
  32. {
  33. $this->level = Logger::toMonologLevel($level);
  34. }
  35. /**
  36. * @inheritDoc
  37. */
  38. public function isHandling(LogRecord $record): bool
  39. {
  40. return $record->level->value >= $this->level->value;
  41. }
  42. /**
  43. * @inheritDoc
  44. */
  45. public function handle(LogRecord $record): bool
  46. {
  47. return $record->level->value >= $this->level->value;
  48. }
  49. }