-
-
Notifications
You must be signed in to change notification settings - Fork 471
Expand file tree
/
Copy pathLogLevel.php
More file actions
99 lines (82 loc) · 2.13 KB
/
Copy pathLogLevel.php
File metadata and controls
99 lines (82 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
declare(strict_types=1);
namespace Sentry\Logs;
/**
* @see: https://develop.sentry.dev/sdk/telemetry/logs/#log-severity-level
*/
class LogLevel
{
/**
* @var string The value of the enum instance
*/
private $value;
/**
* @var int The priority of the log level, used for sorting
*/
private $priority;
/**
* @var array<string, self> A list of cached enum instances
*/
private static $instances = [];
private function __construct(string $value, int $priority)
{
$this->value = $value;
$this->priority = $priority;
}
public static function trace(): self
{
return self::getInstance('trace', 10);
}
public static function debug(): self
{
return self::getInstance('debug', 20);
}
public static function info(): self
{
return self::getInstance('info', 30);
}
public static function warn(): self
{
return self::getInstance('warn', 40);
}
public static function error(): self
{
return self::getInstance('error', 50);
}
public static function fatal(): self
{
return self::getInstance('fatal', 60);
}
public function __toString(): string
{
return $this->value;
}
public function getPriority(): int
{
return $this->priority;
}
public function toPsrLevel(): string
{
switch ($this->value) {
case 'trace':
return \Psr\Log\LogLevel::NOTICE;
case 'debug':
return \Psr\Log\LogLevel::DEBUG;
case 'warn':
return \Psr\Log\LogLevel::WARNING;
case 'error':
return \Psr\Log\LogLevel::ERROR;
case 'fatal':
return \Psr\Log\LogLevel::CRITICAL;
default:
return \Psr\Log\LogLevel::INFO;
}
}
private static function getInstance(string $value, int $priority): self
{
if (!isset(self::$instances[$value])) {
self::$instances[$value] = new self($value, $priority);
}
return self::$instances[$value];
}
}