فهرست منبع

Restore getLevelName but deprecate it

Jordi Boggiano 3 سال پیش
والد
کامیت
c312cfdabf
2فایلهای تغییر یافته به همراه17 افزوده شده و 1 حذف شده
  1. 0 1
      UPGRADE.md
  2. 17 0
      src/Monolog/Logger.php

+ 0 - 1
UPGRADE.md

@@ -28,7 +28,6 @@ Overall / notable changes:
   e.g. instead of `Logger::WARNING` use `Level::Warning` if you need to pass the enum case
   to Monolog or one of its handlers, or `Level::Warning->value` if you need the integer
   value equal to what `Logger::WARNING` was giving you.
-- `Logger::getLevelName` has been removed in favor of `Monolog\Level->toLevelName()->value`.
 - `Logger::$levels` has been removed.
 - `Logger::getLevels` has been removed in favor of `Monolog\Level::VALUES` or `Monolog\Level::cases()`.
 - `setExceptionHandler` now requires a `Closure` instance and not just any `callable`.

+ 17 - 0
src/Monolog/Logger.php

@@ -365,6 +365,23 @@ class Logger implements LoggerInterface, ResettableInterface
         }
     }
 
+    /**
+     * Gets the name of the logging level as a string.
+     *
+     * This still returns a string instead of a LevelName for BC, but new code should not rely on this method.
+     *
+     * @throws \Psr\Log\InvalidArgumentException If level is not defined
+     *
+     * @phpstan-param  Level     $level
+     * @phpstan-return LevelName
+     *
+     * @deprecated Use Monolog\Level->toLevelName()->value instead
+     */
+    public static function getLevelName(int|Level $level): string
+    {
+        return self::toMonologLevel($level)->toLevelName()->value;
+    }
+
     /**
      * Converts PSR-3 levels to Monolog ones if necessary
      *