NullHandler.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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\Logger;
  12. /**
  13. * Blackhole
  14. *
  15. * Any record it can handle will be thrown away. This can be used
  16. * to put on top of an existing stack to override it temporarily.
  17. *
  18. * @author Jordi Boggiano <j.boggiano@seld.be>
  19. */
  20. class NullHandler extends Handler
  21. {
  22. /**
  23. * @var int
  24. */
  25. private $level;
  26. /**
  27. * @param string|int $level The minimum logging level at which this handler will be triggered
  28. */
  29. public function __construct($level = Logger::DEBUG)
  30. {
  31. $this->level = Logger::toMonologLevel($level);
  32. }
  33. /**
  34. * {@inheritdoc}
  35. */
  36. public function isHandling(array $record): bool
  37. {
  38. return $record['level'] >= $this->level;
  39. }
  40. /**
  41. * {@inheritdoc}
  42. */
  43. public function handle(array $record): bool
  44. {
  45. return $record['level'] >= $this->level;
  46. }
  47. }