1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Cmobi\RabbitmqBundle\Logger; |
4
|
|
|
|
5
|
|
|
use Monolog\Handler\StreamHandler; |
6
|
|
|
use Monolog\Logger; |
7
|
|
|
use Psr\Log\LoggerInterface; |
8
|
|
|
|
9
|
|
|
class LogDispatcher implements LoggerInterface |
10
|
|
|
{ |
11
|
|
|
private $log; |
12
|
|
|
|
13
|
|
|
public function __construct($path) |
14
|
|
|
{ |
15
|
|
|
$this->log = new Logger('rabbitmq'); |
16
|
|
|
$this->log->pushHandler(new StreamHandler($path, Logger::WARNING)); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @return Logger |
21
|
|
|
*/ |
22
|
|
|
public function getLog() |
23
|
|
|
{ |
24
|
|
|
return $this->log; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* System is unusable. |
29
|
|
|
* |
30
|
|
|
* @param string $message |
31
|
|
|
* @param array $context |
32
|
|
|
* |
33
|
|
|
* @return null |
34
|
|
|
*/ |
35
|
|
|
public function emergency($message, array $context = array()) |
36
|
|
|
{ |
37
|
|
|
$this->getLog()->emergency($message, $context); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Action must be taken immediately. |
42
|
|
|
* |
43
|
|
|
* Example: Entire website down, database unavailable, etc. This should |
44
|
|
|
* trigger the SMS alerts and wake you up. |
45
|
|
|
* |
46
|
|
|
* @param string $message |
47
|
|
|
* @param array $context |
48
|
|
|
* |
49
|
|
|
* @return null |
50
|
|
|
*/ |
51
|
|
|
public function alert($message, array $context = array()) |
52
|
|
|
{ |
53
|
|
|
$this->getLog()->alert($message, $context); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Critical conditions. |
58
|
|
|
* |
59
|
|
|
* Example: Application component unavailable, unexpected exception. |
60
|
|
|
* |
61
|
|
|
* @param string $message |
62
|
|
|
* @param array $context |
63
|
|
|
* |
64
|
|
|
* @return null |
65
|
|
|
*/ |
66
|
|
|
public function critical($message, array $context = array()) |
67
|
|
|
{ |
68
|
|
|
$this->getLog()->critical($message, $context); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Runtime errors that do not require immediate action but should typically |
73
|
|
|
* be logged and monitored. |
74
|
|
|
* |
75
|
|
|
* @param string $message |
76
|
|
|
* @param array $context |
77
|
|
|
* |
78
|
|
|
* @return null |
79
|
|
|
*/ |
80
|
|
|
public function error($message, array $context = array()) |
81
|
|
|
{ |
82
|
|
|
$this->getLog()->error($message, $context); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Exceptional occurrences that are not errors. |
87
|
|
|
* |
88
|
|
|
* Example: Use of deprecated APIs, poor use of an API, undesirable things |
89
|
|
|
* that are not necessarily wrong. |
90
|
|
|
* |
91
|
|
|
* @param string $message |
92
|
|
|
* @param array $context |
93
|
|
|
* |
94
|
|
|
* @return null |
95
|
|
|
*/ |
96
|
|
|
public function warning($message, array $context = array()) |
97
|
|
|
{ |
98
|
|
|
$this->getLog()->warning($message, $context); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Normal but significant events. |
103
|
|
|
* |
104
|
|
|
* @param string $message |
105
|
|
|
* @param array $context |
106
|
|
|
* |
107
|
|
|
* @return null |
108
|
|
|
*/ |
109
|
|
|
public function notice($message, array $context = array()) |
110
|
|
|
{ |
111
|
|
|
$this->notice($message, $context); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Interesting events. |
116
|
|
|
* |
117
|
|
|
* Example: User logs in, SQL logs. |
118
|
|
|
* |
119
|
|
|
* @param string $message |
120
|
|
|
* @param array $context |
121
|
|
|
* |
122
|
|
|
* @return null |
123
|
|
|
*/ |
124
|
|
|
public function info($message, array $context = array()) |
125
|
|
|
{ |
126
|
|
|
$this->getLog()->info($message, $context); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* Detailed debug information. |
131
|
|
|
* |
132
|
|
|
* @param string $message |
133
|
|
|
* @param array $context |
134
|
|
|
* |
135
|
|
|
* @return null |
136
|
|
|
*/ |
137
|
|
|
public function debug($message, array $context = array()) |
138
|
|
|
{ |
139
|
|
|
$this->getLog()->debug($message, $context); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* Logs with an arbitrary level. |
144
|
|
|
* |
145
|
|
|
* @param mixed $level |
146
|
|
|
* @param string $message |
147
|
|
|
* @param array $context |
148
|
|
|
* |
149
|
|
|
* @return null |
150
|
|
|
*/ |
151
|
|
|
public function log($level, $message, array $context = array()) |
152
|
|
|
{ |
153
|
|
|
$this->getLog()->log($level, $message, $context); |
154
|
|
|
} |
155
|
|
|
} |