1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Console.php |
4
|
|
|
* |
5
|
|
|
* @copyright More in license.md |
6
|
|
|
* @license http://www.ipublikuj.eu |
7
|
|
|
* @author Adam Kadlec http://www.ipublikuj.eu |
8
|
|
|
* @package iPublikuj:MQTTClient! |
9
|
|
|
* @subpackage Logger |
10
|
|
|
* @since 1.0.0 |
11
|
|
|
* |
12
|
|
|
* @date 26.02.17 |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
declare(strict_types = 1); |
16
|
|
|
|
17
|
|
|
namespace IPub\MQTTClient\Logger; |
18
|
|
|
|
19
|
|
|
use Nette; |
20
|
|
|
|
21
|
|
|
use Psr\Log; |
22
|
|
|
|
23
|
|
|
use IPub; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Client server output printer |
27
|
|
|
* |
28
|
|
|
* @package iPublikuj:MQTTClient! |
29
|
|
|
* @subpackage Logger |
30
|
|
|
* |
31
|
|
|
* @author Adam Kadlec <[email protected]> |
32
|
|
|
*/ |
33
|
1 |
|
final class Console implements Log\LoggerInterface |
34
|
|
|
{ |
35
|
|
|
/** |
36
|
|
|
* Implement nette smart magic |
37
|
|
|
*/ |
38
|
1 |
|
use Nette\SmartObject; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var Formatter\IFormatter |
42
|
|
|
*/ |
43
|
|
|
private $formatter; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param Formatter\IFormatter $formatter |
47
|
|
|
* |
48
|
|
|
* @return void |
49
|
|
|
*/ |
50
|
|
|
public function setFormatter(Formatter\IFormatter $formatter) |
51
|
|
|
{ |
52
|
|
|
$this->formatter = $formatter; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* {@inheritdoc} |
57
|
|
|
*/ |
58
|
|
|
public function emergency($message, array $context = []) |
59
|
|
|
{ |
60
|
|
|
if ($this->formatter) { |
61
|
|
|
$this->formatter->caution($message); |
62
|
|
|
|
63
|
|
|
} else { |
64
|
|
|
echo 'CAUTION! '; |
65
|
|
|
|
66
|
|
|
$this->writeln($message); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* {@inheritdoc} |
72
|
|
|
*/ |
73
|
|
|
public function alert($message, array $context = []) |
74
|
|
|
{ |
75
|
|
|
if ($this->formatter) { |
76
|
|
|
$this->formatter->error($message); |
77
|
|
|
|
78
|
|
|
} else { |
79
|
|
|
echo 'ERROR! '; |
80
|
|
|
|
81
|
|
|
$this->writeln($message); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* {@inheritdoc} |
87
|
|
|
*/ |
88
|
|
|
public function critical($message, array $context = []) |
89
|
|
|
{ |
90
|
|
|
if ($this->formatter) { |
91
|
|
|
$this->formatter->error($message); |
92
|
|
|
|
93
|
|
|
} else { |
94
|
|
|
echo 'ERROR! '; |
95
|
|
|
|
96
|
|
|
$this->writeln($message); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* {@inheritdoc} |
102
|
|
|
*/ |
103
|
|
|
public function error($message, array $context = []) |
104
|
|
|
{ |
105
|
|
|
if ($this->formatter) { |
106
|
|
|
$this->formatter->error($message); |
107
|
|
|
|
108
|
|
|
} else { |
109
|
|
|
echo 'ERROR! '; |
110
|
|
|
|
111
|
|
|
$this->writeln($message); |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* {@inheritdoc} |
117
|
|
|
*/ |
118
|
|
|
public function warning($message, array $context = []) |
119
|
|
|
{ |
120
|
|
|
if ($this->formatter) { |
121
|
|
|
$this->formatter->warning($message); |
122
|
|
|
|
123
|
|
|
} else { |
124
|
|
|
echo 'WARNING! '; |
125
|
|
|
|
126
|
|
|
$this->writeln($message); |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* {@inheritdoc} |
132
|
|
|
*/ |
133
|
|
|
public function notice($message, array $context = []) |
134
|
|
|
{ |
135
|
|
|
if ($this->formatter) { |
136
|
|
|
$this->formatter->note($message); |
137
|
|
|
|
138
|
|
|
} else { |
139
|
|
|
echo 'NOTICE! '; |
140
|
|
|
|
141
|
|
|
$this->writeln($message); |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* {@inheritdoc} |
147
|
|
|
*/ |
148
|
|
|
public function info($message, array $context = []) |
149
|
|
|
{ |
150
|
|
|
if ($this->formatter) { |
151
|
|
|
$this->formatter->note($message); |
152
|
|
|
|
153
|
|
|
} else { |
154
|
|
|
echo 'INFO: '; |
155
|
|
|
|
156
|
|
|
$this->writeln($message); |
157
|
|
|
} |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* {@inheritdoc} |
162
|
|
|
*/ |
163
|
|
|
public function debug($message, array $context = []) |
164
|
|
|
{ |
165
|
|
|
if ($this->formatter) { |
166
|
|
|
$this->formatter->note($message); |
167
|
|
|
|
168
|
|
|
} else { |
169
|
|
|
echo 'DEBUG: '; |
170
|
|
|
|
171
|
|
|
$this->writeln($message); |
172
|
|
|
} |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* {@inheritdoc} |
177
|
|
|
*/ |
178
|
|
|
public function log($level, $message, array $context = []) |
179
|
|
|
{ |
180
|
|
|
if ($this->formatter) { |
181
|
|
|
$this->formatter->note($message); |
182
|
|
|
|
183
|
|
|
} else { |
184
|
|
|
echo 'LOG: '; |
185
|
|
|
|
186
|
|
|
$this->writeln($message); |
187
|
|
|
} |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* @param string $message |
192
|
|
|
*/ |
193
|
|
|
private function writeln(string $message) |
194
|
|
|
{ |
195
|
|
|
if ($this->formatter) { |
196
|
|
|
$this->formatter->writeln($message); |
|
|
|
|
197
|
|
|
|
198
|
|
|
} else { |
199
|
|
|
echo $message . "\r\n"; |
200
|
|
|
} |
201
|
|
|
} |
202
|
|
|
} |
203
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.