1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @copyright Copyright (c) Flipbox Digital Limited |
5
|
|
|
* @license https://github.com/flipbox/skeleton/blob/master/LICENSE |
6
|
|
|
* @link https://github.com/flipbox/skeleton |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Flipbox\Skeleton\Logger; |
10
|
|
|
|
11
|
|
|
use Psr\Log\LogLevel; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @author Flipbox Factory <[email protected]> |
15
|
|
|
* @since 2.0.0 |
16
|
|
|
*/ |
17
|
|
|
trait StaticLoggerTrait |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* System is unusable. |
21
|
|
|
* |
22
|
|
|
* @param string $message |
23
|
|
|
* @param array $context |
24
|
|
|
*/ |
25
|
|
|
public static function emergency($message, array $context = []) |
26
|
|
|
{ |
27
|
|
|
self::log(LogLevel::EMERGENCY, $message, $context); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Action must be taken immediately. |
32
|
|
|
* |
33
|
|
|
* Example: Entire website down, database unavailable, etc. This should |
34
|
|
|
* trigger the SMS alerts and wake you up. |
35
|
|
|
* |
36
|
|
|
* @param string $message |
37
|
|
|
* @param array $context |
38
|
|
|
*/ |
39
|
|
|
public static function alert($message, array $context = []) |
40
|
|
|
{ |
41
|
|
|
self::log(LogLevel::ALERT, $message, $context); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Critical conditions. |
46
|
|
|
* |
47
|
|
|
* Example: Application component unavailable, unexpected exception. |
48
|
|
|
* |
49
|
|
|
* @param string $message |
50
|
|
|
* @param array $context |
51
|
|
|
*/ |
52
|
|
|
public static function critical($message, array $context = []) |
53
|
|
|
{ |
54
|
|
|
self::log(LogLevel::CRITICAL, $message, $context); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Runtime errors that do not require immediate action but should typically |
59
|
|
|
* be logged and monitored. |
60
|
|
|
* |
61
|
|
|
* @param string $message |
62
|
|
|
* @param array $context |
63
|
|
|
*/ |
64
|
|
|
public static function error($message, array $context = []) |
65
|
|
|
{ |
66
|
|
|
self::log(LogLevel::ERROR, $message, $context); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Exceptional occurrences that are not errors. |
71
|
|
|
* |
72
|
|
|
* Example: Use of deprecated APIs, poor use of an API, undesirable things |
73
|
|
|
* that are not necessarily wrong. |
74
|
|
|
* |
75
|
|
|
* @param string $message |
76
|
|
|
* @param array $context |
77
|
|
|
*/ |
78
|
|
|
public static function warning($message, array $context = []) |
79
|
|
|
{ |
80
|
|
|
self::log(LogLevel::WARNING, $message, $context); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Normal but significant events. |
85
|
|
|
* |
86
|
|
|
* @param string $message |
87
|
|
|
* @param array $context |
88
|
|
|
*/ |
89
|
|
|
public static function notice($message, array $context = []) |
90
|
|
|
{ |
91
|
|
|
self::log(LogLevel::NOTICE, $message, $context); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Interesting events. |
96
|
|
|
* |
97
|
|
|
* Example: User logs in, SQL logs. |
98
|
|
|
* |
99
|
|
|
* @param string $message |
100
|
|
|
* @param array $context |
101
|
|
|
*/ |
102
|
|
|
public static function info($message, array $context = []) |
103
|
|
|
{ |
104
|
|
|
self::log(LogLevel::INFO, $message, $context); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Detailed debug information. |
109
|
|
|
* |
110
|
|
|
* @param string $message |
111
|
|
|
* @param array $context |
112
|
|
|
*/ |
113
|
|
|
public static function debug($message, array $context = []) |
114
|
|
|
{ |
115
|
|
|
self::log(LogLevel::DEBUG, $message, $context); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Logs with an arbitrary level. |
120
|
|
|
* |
121
|
|
|
* @param mixed $level |
122
|
|
|
* @param string $message |
123
|
|
|
* @param array $context |
124
|
|
|
*/ |
125
|
|
|
abstract public static function log($level, $message, array $context = []); |
126
|
|
|
} |
127
|
|
|
|