friendica-addons/monolog/vendor/monolog/monolog/src/Monolog/Handler/NullHandler.php

61 lines
1.3 KiB
PHP
Raw Normal View History

2022-10-17 21:25:03 +02:00
<?php declare(strict_types=1);
/*
* This file is part of the Monolog package.
*
* (c) Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Monolog\Handler;
use Monolog\Logger;
2023-01-18 00:17:49 +01:00
use Psr\Log\LogLevel;
2022-10-17 21:25:03 +02:00
/**
* Blackhole
*
* Any record it can handle will be thrown away. This can be used
* to put on top of an existing stack to override it temporarily.
*
* @author Jordi Boggiano <j.boggiano@seld.be>
2023-01-18 00:17:49 +01:00
*
* @phpstan-import-type Level from \Monolog\Logger
* @phpstan-import-type LevelName from \Monolog\Logger
2022-10-17 21:25:03 +02:00
*/
class NullHandler extends Handler
{
2023-01-18 00:17:49 +01:00
/**
* @var int
*/
private $level;
2022-10-17 21:25:03 +02:00
/**
2023-01-18 00:17:49 +01:00
* @param string|int $level The minimum logging level at which this handler will be triggered
2022-10-17 21:25:03 +02:00
*
2023-01-18 00:17:49 +01:00
* @phpstan-param Level|LevelName|LogLevel::* $level
2022-10-17 21:25:03 +02:00
*/
2023-01-18 00:17:49 +01:00
public function __construct($level = Logger::DEBUG)
2022-10-17 21:25:03 +02:00
{
$this->level = Logger::toMonologLevel($level);
}
/**
2023-01-18 00:17:49 +01:00
* {@inheritDoc}
2022-10-17 21:25:03 +02:00
*/
2023-01-18 00:17:49 +01:00
public function isHandling(array $record): bool
2022-10-17 21:25:03 +02:00
{
2023-01-18 00:17:49 +01:00
return $record['level'] >= $this->level;
2022-10-17 21:25:03 +02:00
}
/**
2023-01-18 00:17:49 +01:00
* {@inheritDoc}
2022-10-17 21:25:03 +02:00
*/
2023-01-18 00:17:49 +01:00
public function handle(array $record): bool
2022-10-17 21:25:03 +02:00
{
2023-01-18 00:17:49 +01:00
return $record['level'] >= $this->level;
2022-10-17 21:25:03 +02:00
}
}