‪TYPO3CMS  ‪main
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 
55  public static function ‪getInternalName(int $level): string
56  {
57  ‪self::validateLevel($level);
58  return static::$levels[$level];
59  }
60 
68  public static function ‪isValidLevel(int $level): bool
69  {
70  return isset(static::$levels[$level]);
71  }
72 
79  public static function ‪validateLevel(int $level): void
80  {
81  if (!self::isValidLevel($level)) {
82  throw new InvalidArgumentException('Invalid Log Level ' . $level, 1321637121);
83  }
84  }
85 
91  public static function ‪normalizeLevel($level): int
92  {
93  if (is_string($level)) {
94  if (!defined(__CLASS__ . '::' . strtoupper($level))) {
95  throw new InvalidArgumentException('Invalid Log Level ' . $level, 1550247164);
96  }
97  return array_search(strtolower($level), self::$levels, true);
98  }
99 
100  return (int)$level;
101  }
102 
109  public static function ‪atLeast($level): array
110  {
111  $level = ‪self::normalizeLevel($level);
112  return array_filter(self::$levels, static fn(int $intLevel): bool => $intLevel <= $level, ARRAY_FILTER_USE_KEY);
113  }
114 }
‪TYPO3\CMS\Core\Log\LogLevel\normalizeLevel
‪static normalizeLevel($level)
Definition: LogLevel.php:90
‪TYPO3\CMS\Core\Log
Definition: Channel.php:18
‪TYPO3\CMS\Core\Log\LogLevel\validateLevel
‪static validateLevel(int $level)
Definition: LogLevel.php:78
‪TYPO3\CMS\Core\Log\LogLevel\getInternalName
‪static getInternalName(int $level)
Definition: LogLevel.php:54
‪TYPO3\CMS\Core\Log\LogLevel\$levels
‪static array $levels
Definition: LogLevel.php:29
‪TYPO3\CMS\Core\Log\LogLevel\atLeast
‪static array< string > atLeast($level)
Definition: LogLevel.php:108
‪TYPO3\CMS\Core\Log\LogLevel
Definition: LogLevel.php:24
‪TYPO3\CMS\Core\Log\LogLevel\isValidLevel
‪static bool isValidLevel(int $level)
Definition: LogLevel.php:67
‪TYPO3\CMS\Core\Log\LogLevel\getName
‪static string getName(int $level)
Definition: LogLevel.php:46