1<?php declare(strict_types=1); 2 3/* 4 * This file is part of the Monolog package. 5 * 6 * (c) Jordi Boggiano <j.boggiano@seld.be> 7 * 8 * For the full copyright and license information, please view the LICENSE 9 * file that was distributed with this source code. 10 */ 11 12namespace Monolog\Handler; 13 14use Monolog\Logger; 15use Psr\Log\LogLevel; 16 17/** 18 * Blackhole 19 * 20 * Any record it can handle will be thrown away. This can be used 21 * to put on top of an existing stack to override it temporarily. 22 * 23 * @author Jordi Boggiano <j.boggiano@seld.be> 24 * 25 * @phpstan-import-type Level from \Monolog\Logger 26 * @phpstan-import-type LevelName from \Monolog\Logger 27 */ 28class NullHandler extends Handler 29{ 30 /** 31 * @var int 32 */ 33 private $level; 34 35 /** 36 * @param string|int $level The minimum logging level at which this handler will be triggered 37 * 38 * @phpstan-param Level|LevelName|LogLevel::* $level 39 */ 40 public function __construct($level = Logger::DEBUG) 41 { 42 $this->level = Logger::toMonologLevel($level); 43 } 44 45 /** 46 * {@inheritDoc} 47 */ 48 public function isHandling(array $record): bool 49 { 50 return $record['level'] >= $this->level; 51 } 52 53 /** 54 * {@inheritDoc} 55 */ 56 public function handle(array $record): bool 57 { 58 return $record['level'] >= $this->level; 59 } 60} 61