‪TYPO3CMS  10.4
LogLevel.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
16 namespace ‪TYPO3\CMS\Core\Log;
17 
18 use Psr\Log\InvalidArgumentException;
19 
23 class ‪LogLevel extends \Psr\Log\LogLevel
24 {
30  protected static ‪$levels = [
31  self::EMERGENCY,
32  self::ALERT,
33  self::CRITICAL,
34  self::ERROR,
35  self::WARNING,
36  self::NOTICE,
37  self::INFO,
38  self::DEBUG,
39  ];
40 
47  public static function ‪getName(int $level): string
48  {
49  return strtoupper(static::getInternalName($level));
50  }
51 
58  public static function ‪getInternalName(int $level): string
59  {
60  ‪self::validateLevel($level);
61  return static::$levels[$level];
62  }
63 
71  public static function ‪isValidLevel(int $level): bool
72  {
73  return isset(static::$levels[$level]);
74  }
75 
82  public static function ‪validateLevel(int $level): void
83  {
84  if (!self::isValidLevel($level)) {
85  throw new InvalidArgumentException('Invalid Log Level ' . $level, 1321637121);
86  }
87  }
88 
95  public static function ‪normalizeLevel($level): int
96  {
97  if (is_string($level)) {
98  if (!defined(__CLASS__ . '::' . strtoupper($level))) {
99  throw new InvalidArgumentException('Invalid Log Level ' . $level, 1550247164);
100  }
101  return array_search(strtolower($level), self::$levels, true);
102  }
103 
104  return (int)$level;
105  }
106 }
‪TYPO3\CMS\Core\Log
‪TYPO3\CMS\Core\Log\LogLevel\validateLevel
‪static validateLevel(int $level)
Definition: LogLevel.php:81
‪TYPO3\CMS\Core\Log\LogLevel\getInternalName
‪static string getInternalName(int $level)
Definition: LogLevel.php:57
‪TYPO3\CMS\Core\Log\LogLevel\$levels
‪static array $levels
Definition: LogLevel.php:29
‪TYPO3\CMS\Core\Log\LogLevel\normalizeLevel
‪static int normalizeLevel($level)
Definition: LogLevel.php:94
‪TYPO3\CMS\Core\Log\LogLevel
Definition: LogLevel.php:24
‪TYPO3\CMS\Core\Log\LogLevel\isValidLevel
‪static bool isValidLevel(int $level)
Definition: LogLevel.php:70
‪TYPO3\CMS\Core\Log\LogLevel\getName
‪static string getName(int $level)
Definition: LogLevel.php:46