-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLogger.php
159 lines (145 loc) · 3.69 KB
/
Logger.php
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<?php
namespace FsDeliverySdk\Log;
class Logger implements LoggerInterface
{
private $filePath = '/tmp/debug.txt';
/**
* @return string
*/
public function getFilePath()
{
return $this->filePath;
}
/**
* @param string $filePath
*/
public function setFilePath($filePath)
{
$this->filePath = $filePath;
}
/**
* Write log string to file
*
* @param string $level
* @param string|\Stringable $message
* @param mixed[] $context
*
* @return void
*/
private function writeLog($level, $message, $context = []) {
$log = "\n[".date('c').'] name.'.$level.': '.$message.' '.json_encode($context);
file_put_contents($this->filePath, $log, FILE_APPEND);
}
/**
* System is unusable.
*
* @param string|\Stringable $message
* @param mixed[] $context
*
* @return void
*/
public function emergency($message, $context = []) {
$this->writeLog('EMERGENCY', $message, $context);
}
/**
* Action must be taken immediately.
*
* Example: Entire website down, database unavailable, etc. This should
* trigger the SMS alerts and wake you up.
*
* @param string|\Stringable $message
* @param mixed[] $context
*
* @return void
*/
public function alert($message, $context = []) {
$this->writeLog('ALERT', $message, $context);
}
/**
* Critical conditions.
*
* Example: Application component unavailable, unexpected exception.
*
* @param string|\Stringable $message
* @param mixed[] $context
*
* @return void
*/
public function critical($message, $context = []) {
$this->writeLog('CRITICAL', $message, $context);
}
/**
* Runtime errors that do not require immediate action but should typically
* be logged and monitored.
*
* @param string|\Stringable $message
* @param mixed[] $context
*
* @return void
*/
public function error($message, $context = []) {
$this->writeLog('ERROR', $message, $context);
}
/**
* Exceptional occurrences that are not errors.
*
* Example: Use of deprecated APIs, poor use of an API, undesirable things
* that are not necessarily wrong.
*
* @param string|\Stringable $message
* @param mixed[] $context
*
* @return void
*/
public function warning($message, $context = []) {
$this->writeLog('WARNING', $message, $context);
}
/**
* Normal but significant events.
*
* @param string|\Stringable $message
* @param mixed[] $context
*
* @return void
*/
public function notice($message, $context = []) {
$this->writeLog('NOTICE', $message, $context);
}
/**
* Interesting events.
*
* Example: User logs in, SQL logs.
*
* @param string|\Stringable $message
* @param mixed[] $context
*
* @return void
*/
public function info($message, $context = []) {
$this->writeLog('INFO', $message, $context);
}
/**
* Detailed debug information.
*
* @param string|\Stringable $message
* @param mixed[] $context
*
* @return void
*/
public function debug($message, $context = []) {
$this->writeLog('DEBUG', $message, $context);
}
/**
* Logs with an arbitrary level.
*
* @param mixed $level
* @param string|\Stringable $message
* @param mixed[] $context
*
* @return void
* @throws \Exception
*/
public function log($level, $message, $context = []) {
throw new \Exception('Method not supported!');
}
}