mirror of
https://github.com/Seldaek/monolog.git
synced 2025-10-21 16:46:11 +02:00
Convert level/levelName to enums (#1656)
This commit is contained in:
@@ -11,6 +11,8 @@
|
||||
|
||||
namespace Monolog\Processor;
|
||||
|
||||
use Monolog\Level;
|
||||
use Monolog\LevelName;
|
||||
use Monolog\Logger;
|
||||
use Psr\Log\LogLevel;
|
||||
use Monolog\LogRecord;
|
||||
@@ -20,23 +22,19 @@ use Monolog\LogRecord;
|
||||
*
|
||||
* @author Nick Otter
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
*
|
||||
* @phpstan-import-type Level from \Monolog\Logger
|
||||
* @phpstan-import-type LevelName from \Monolog\Logger
|
||||
*/
|
||||
class GitProcessor implements ProcessorInterface
|
||||
{
|
||||
/** @var int */
|
||||
private $level;
|
||||
private Level $level;
|
||||
/** @var array{branch: string, commit: string}|array<never>|null */
|
||||
private static $cache = null;
|
||||
|
||||
/**
|
||||
* @param string|int $level The minimum logging level at which this Processor will be triggered
|
||||
* @param int|string|Level|LevelName|LogLevel::* $level The minimum logging level at which this Processor will be triggered
|
||||
*
|
||||
* @phpstan-param Level|LevelName|LogLevel::* $level
|
||||
* @phpstan-param value-of<Level::VALUES>|value-of<LevelName::VALUES>|Level|LevelName|LogLevel::* $level
|
||||
*/
|
||||
public function __construct($level = Logger::DEBUG)
|
||||
public function __construct(int|string|Level|LevelName $level = Level::Debug)
|
||||
{
|
||||
$this->level = Logger::toMonologLevel($level);
|
||||
}
|
||||
|
@@ -11,6 +11,8 @@
|
||||
|
||||
namespace Monolog\Processor;
|
||||
|
||||
use Monolog\Level;
|
||||
use Monolog\LevelName;
|
||||
use Monolog\Logger;
|
||||
use Psr\Log\LogLevel;
|
||||
use Monolog\LogRecord;
|
||||
@@ -25,13 +27,10 @@ use Monolog\LogRecord;
|
||||
* triggered the FingersCrossedHandler.
|
||||
*
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
*
|
||||
* @phpstan-import-type Level from \Monolog\Logger
|
||||
* @phpstan-import-type LevelName from \Monolog\Logger
|
||||
*/
|
||||
class IntrospectionProcessor implements ProcessorInterface
|
||||
{
|
||||
private int $level;
|
||||
private Level $level;
|
||||
|
||||
/** @var string[] */
|
||||
private array $skipClassesPartials;
|
||||
@@ -44,12 +43,12 @@ class IntrospectionProcessor implements ProcessorInterface
|
||||
];
|
||||
|
||||
/**
|
||||
* @param string|int $level The minimum logging level at which this Processor will be triggered
|
||||
* @param string|int|Level|LevelName $level The minimum logging level at which this Processor will be triggered
|
||||
* @param string[] $skipClassesPartials
|
||||
*
|
||||
* @phpstan-param Level|LevelName|LogLevel::* $level
|
||||
* @phpstan-param value-of<Level::VALUES>|value-of<LevelName::VALUES>|Level|LevelName|LogLevel::* $level
|
||||
*/
|
||||
public function __construct($level = Logger::DEBUG, array $skipClassesPartials = [], int $skipStackFramesCount = 0)
|
||||
public function __construct(int|string|Level|LevelName $level = Level::Debug, array $skipClassesPartials = [], int $skipStackFramesCount = 0)
|
||||
{
|
||||
$this->level = Logger::toMonologLevel($level);
|
||||
$this->skipClassesPartials = array_merge(['Monolog\\'], $skipClassesPartials);
|
||||
@@ -62,7 +61,7 @@ class IntrospectionProcessor implements ProcessorInterface
|
||||
public function __invoke(LogRecord $record): LogRecord
|
||||
{
|
||||
// return if the level is not high enough
|
||||
if ($record->level < $this->level) {
|
||||
if ($record->level->isLowerThan($this->level)) {
|
||||
return $record;
|
||||
}
|
||||
|
||||
|
@@ -11,6 +11,8 @@
|
||||
|
||||
namespace Monolog\Processor;
|
||||
|
||||
use Monolog\Level;
|
||||
use Monolog\LevelName;
|
||||
use Monolog\Logger;
|
||||
use Psr\Log\LogLevel;
|
||||
use Monolog\LogRecord;
|
||||
@@ -19,23 +21,19 @@ use Monolog\LogRecord;
|
||||
* Injects Hg branch and Hg revision number in all records
|
||||
*
|
||||
* @author Jonathan A. Schweder <jonathanschweder@gmail.com>
|
||||
*
|
||||
* @phpstan-import-type LevelName from \Monolog\Logger
|
||||
* @phpstan-import-type Level from \Monolog\Logger
|
||||
*/
|
||||
class MercurialProcessor implements ProcessorInterface
|
||||
{
|
||||
/** @var Level */
|
||||
private $level;
|
||||
private Level $level;
|
||||
/** @var array{branch: string, revision: string}|array<never>|null */
|
||||
private static $cache = null;
|
||||
|
||||
/**
|
||||
* @param int|string $level The minimum logging level at which this Processor will be triggered
|
||||
* @param int|string|Level|LevelName $level The minimum logging level at which this Processor will be triggered
|
||||
*
|
||||
* @phpstan-param Level|LevelName|LogLevel::* $level
|
||||
* @phpstan-param value-of<Level::VALUES>|value-of<LevelName::VALUES>|Level|LevelName|LogLevel::* $level
|
||||
*/
|
||||
public function __construct($level = Logger::DEBUG)
|
||||
public function __construct(int|string|Level|LevelName $level = Level::Debug)
|
||||
{
|
||||
$this->level = Logger::toMonologLevel($level);
|
||||
}
|
||||
@@ -46,7 +44,7 @@ class MercurialProcessor implements ProcessorInterface
|
||||
public function __invoke(LogRecord $record): LogRecord
|
||||
{
|
||||
// return if the level is not high enough
|
||||
if ($record->level < $this->level) {
|
||||
if ($record->level->isLowerThan($this->level)) {
|
||||
return $record;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user