-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLevel.php
More file actions
77 lines (70 loc) · 2.56 KB
/
Level.php
File metadata and controls
77 lines (70 loc) · 2.56 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
<?php
//
// +---------------------------------------------------------+
// | Level.php |
// +---------------------------------------------------------+
// | Put your description here |
// +---------------------------------------------------------+
// | Copyright (©) 2021 |
// +---------------------------------------------------------+
// | Authors: Mehernosh Mohta <emnosh.pro@gmail.com.au> |
// +---------------------------------------------------------+
//
namespace EM\Log;
/**
* Describes log levels.
*/
class Level
{
const EMERGENCY = 'emergency';
const ALERT = 'alert';
const CRITICAL = 'critical';
const ERROR = 'error';
const WARNING = 'warning';
const NOTICE = 'notice';
const INFO = 'info';
const DEBUG = 'debug';
protected static $log_level_types = [
self::EMERGENCY => 0,
self::ALERT => 1,
self::CRITICAL => 2,
self::ERROR => 3,
self::WARNING => 4,
self::NOTICE => 5,
self::INFO => 6,
self::DEBUG => 7
];
protected static $core_level_map = [
E_ERROR => 'error',
E_PARSE => 'error',
E_CORE_ERROR => 'error',
E_COMPILE_ERROR => 'error',
E_RECOVERABLE_ERROR => 'error',
E_ALL => 'error',
E_USER_ERROR => 'error',
E_NOTICE => 'notice',
E_USER_NOTICE => 'notice',
E_CORE_WARNING => 'warning',
E_WARNING => 'warning',
E_USER_WARNING => 'warning',
E_STRICT => 'info',
E_DEPRECATED => 'info',
];
public static function getLogLevel($log_level = self::DEBUG): int
{
if (isset(self::$log_level_types[$log_level])) {
return self::$log_level_types[$log_level];
}
return self::$log_level_types[self::DEBUG];
}
public static function getCoreLevelMap($error_no = E_WARNING): string
{
// PHP Core error constants to be mapped
// such that they can be passed to relevant
// logger functions
if (isset(self::$core_level_map[$error_no])) {
return self::$core_level_map[$error_no];
}
return 'info';
}
}