Repository navigation
Expand file tree
/
Copy pathLogger.php
More file actions
executable file
·220 lines (203 loc) · 5.67 KB
/
Copy pathLogger.php
File metadata and controls
executable file
·220 lines (203 loc) · 5.67 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
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
<?php
/**
* Webiny Framework (http://www.webiny.com/framework)
*
* @copyright Copyright Webiny LTD
*/
namespace Webiny\Component\Logger;
use Webiny\Component\Logger\Bridge\LoggerAbstract;
use Webiny\Component\Logger\Bridge\LoggerDriverInterface;
use Webiny\Component\Logger\Driver\NullDriver;
use Webiny\Component\Logger\Driver\Webiny;
use Webiny\Component\StdLib\ComponentTrait;
use Webiny\Component\StdLib\StdLibTrait;
/**
* Webiny Logger is used to log any kind of messages.<br />
* The way you log a message can be implement through a driver, message handler and message formatter
*
* @package Webiny\Component\Logger
*/
class Logger
{
use StdLibTrait, ComponentTrait;
private static $defaultConfig = [
'Parameters' => [
'Logger.Class' => Logger::class,
'Logger.Driver.Class' => NullDriver::class
],
'Services' => [
'Webiny' => [
'Class' => '%Logger.Class%',
'Arguments' => [
'System',
'%Logger.Driver.Class%'
]
]
]
];
/**
* @var null
*/
private $driverInstance = null;
/**
* Create new logger using given name and driver.<br>
* A name is used to identify log messages from different loggers.<br><br>
* Having two loggers ("Payment Gateway" and "Invoice Payment") would result in the following output:<br>
* <br>
* [Payment Gateway][info] Request sent.<br>
* [Invoice Payment][alert] Paid invoice amount is too small.
*
*
* @param string $name Logger name
* @param LoggerDriverInterface $driverInstance
*
* @return \Webiny\Component\Logger\Logger
*/
public function __construct($name, $driverInstance)
{
$this->driverInstance = $driverInstance;
$this->driverInstance->setName($name);
}
/**
* Call a method on driver instance
* Since we are wrapping an actual driver instance with this Logger object, we need a way to implement this magic method to forward the call to driver instance
*
* @param $name
* @param $arguments
*
* @return mixed
* @throws LoggerException
*/
public function __call($name, $arguments)
{
if (method_exists($this->driverInstance, $name)) {
return call_user_func_array([
$this->driverInstance,
$name
], $arguments
);
}
throw new LoggerException('Call to undefined method "' . $name . '" on Logger object! Make sure your logger driver provides the required method!'
);
}
/**
* System is unusable.
*
* @param string $message
* @param array $context
*
* @return null
*/
public function emergency($message, array $context = array())
{
$this->driverInstance->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 $message
* @param array $context
*
* @return null
*/
public function alert($message, array $context = array())
{
$this->driverInstance->alert($message, $context);
}
/**
* Critical conditions.
*
* Example: Application component unavailable, unexpected exception.
*
* @param string $message
* @param array $context
*
* @return null
*/
public function critical($message, array $context = array())
{
$this->driverInstance->critical($message, $context);
}
/**
* Runtime errors that do not require immediate action but should typically
* be logged and monitored.
*
* @param string $message
* @param array $context
*
* @return null
*/
public function error($message, array $context = array())
{
$this->driverInstance->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 $message
* @param array $context
*
* @return null
*/
public function warning($message, array $context = array())
{
$this->driverInstance->warning($message, $context);
}
/**
* Normal but significant events.
*
* @param string $message
* @param array $context
*
* @return null
*/
public function notice($message, array $context = array())
{
$this->driverInstance->notice($message, $context);
}
/**
* Interesting events.
*
* Example: User logs in, SQL logs.
*
* @param string $message
* @param array $context
*
* @return null
*/
public function info($message, array $context = array())
{
$this->driverInstance->info($message, $context);
}
/**
* Detailed debug information.
*
* @param string $message
* @param array $context
*
* @return null
*/
public function debug($message, array $context = array())
{
$this->driverInstance->debug($message, $context);
}
/**
* Logs with an arbitrary level.
*
* @param mixed $level
* @param string $message
* @param array $context
*
* @return null
*/
public function log($level, $message, array $context = array())
{
$this->driverInstance->log($level, $message, $context);
}
}