1 | <?php |
||
25 | class Logger extends AbstractLogger // extends ConsoleLogger |
||
26 | { |
||
27 | /** |
||
28 | * @var OutputInterface |
||
29 | */ |
||
30 | protected $output; |
||
31 | /** |
||
32 | * @var OutputInterface |
||
33 | */ |
||
34 | protected $error; |
||
35 | /** |
||
36 | * @var LogOutputStylerInterface |
||
37 | */ |
||
38 | protected $outputStyler; |
||
39 | /** |
||
40 | * @var OutputInterface|SymfonyStyle|other |
||
41 | */ |
||
42 | protected $outputStreamWrapper; |
||
43 | protected $errorStreamWrapper; |
||
44 | |||
45 | protected $formatFunctionMap = [ |
||
46 | LogLevel::EMERGENCY => 'error', |
||
47 | LogLevel::ALERT => 'error', |
||
48 | LogLevel::CRITICAL => 'error', |
||
49 | LogLevel::ERROR => 'error', |
||
50 | LogLevel::WARNING => 'warning', |
||
51 | LogLevel::NOTICE => 'note', |
||
52 | LogLevel::INFO => 'note', |
||
53 | LogLevel::DEBUG => 'note', |
||
54 | ConsoleLogLevel::SUCCESS => 'success', |
||
55 | ]; |
||
56 | |||
57 | /** |
||
58 | * @param OutputInterface $output |
||
59 | * @param array $verbosityLevelMap |
||
60 | * @param array $formatLevelMap |
||
61 | * @param array $formatFunctionMap |
||
62 | */ |
||
63 | public function __construct(OutputInterface $output, array $verbosityLevelMap = array(), array $formatLevelMap = array(), array $formatFunctionMap = array()) |
||
71 | |||
72 | public function setLogOutputStyler(LogOutputStylerInterface $outputStyler, array $formatFunctionMap = array()) |
||
79 | |||
80 | public function getLogOutputStyler() |
||
87 | |||
88 | protected function getOutputStream() |
||
92 | |||
93 | protected function getErrorStream() |
||
104 | |||
105 | public function setOutputStream($output) |
||
110 | |||
111 | public function setErrorStream($error) |
||
116 | |||
117 | protected function getOutputStreamWrapper() |
||
124 | |||
125 | protected function getErrorStreamWrapper() |
||
132 | |||
133 | protected function getOutputStreamForLogLevel($level) |
||
143 | |||
144 | /** |
||
145 | * {@inheritdoc} |
||
146 | */ |
||
147 | public function log($level, $message, array $context = array()) |
||
174 | |||
175 | /** |
||
176 | * Interpolate and style the message, and then send it to the log. |
||
177 | */ |
||
178 | protected function doLog($outputStreamWrapper, $level, $message, $context) |
||
195 | |||
196 | public function success($message, array $context = array()) |
||
200 | |||
201 | // The functions below could be eliminated if made `protected` intead |
||
202 | // of `private` in ConsoleLogger |
||
203 | |||
204 | const INFO = 'info'; |
||
205 | const ERROR = 'error'; |
||
206 | |||
207 | /** |
||
208 | * @var OutputInterface |
||
209 | */ |
||
210 | //private $output; |
||
211 | /** |
||
212 | * @var array |
||
213 | */ |
||
214 | private $verbosityLevelMap = [ |
||
215 | LogLevel::EMERGENCY => OutputInterface::VERBOSITY_NORMAL, |
||
216 | LogLevel::ALERT => OutputInterface::VERBOSITY_NORMAL, |
||
217 | LogLevel::CRITICAL => OutputInterface::VERBOSITY_NORMAL, |
||
218 | LogLevel::ERROR => OutputInterface::VERBOSITY_NORMAL, |
||
219 | LogLevel::WARNING => OutputInterface::VERBOSITY_NORMAL, |
||
220 | LogLevel::NOTICE => OutputInterface::VERBOSITY_VERBOSE, |
||
221 | LogLevel::INFO => OutputInterface::VERBOSITY_VERY_VERBOSE, |
||
222 | LogLevel::DEBUG => OutputInterface::VERBOSITY_DEBUG, |
||
223 | ConsoleLogLevel::SUCCESS => OutputInterface::VERBOSITY_NORMAL, |
||
224 | ]; |
||
225 | |||
226 | /** |
||
227 | * @var array |
||
228 | * |
||
229 | * Send all log messages to stderr. Symfony should have the same default. |
||
230 | * See: https://en.wikipedia.org/wiki/Standard_streams |
||
231 | * "Standard error was added to Unix after several wasted phototypesetting runs ended with error messages being typeset instead of displayed on the user's terminal." |
||
232 | * |
||
233 | */ |
||
234 | private $formatLevelMap = [ |
||
235 | LogLevel::EMERGENCY => self::ERROR, |
||
236 | LogLevel::ALERT => self::ERROR, |
||
237 | LogLevel::CRITICAL => self::ERROR, |
||
238 | LogLevel::ERROR => self::ERROR, |
||
239 | LogLevel::WARNING => self::ERROR, |
||
240 | LogLevel::NOTICE => self::ERROR, |
||
241 | LogLevel::INFO => self::ERROR, |
||
242 | LogLevel::DEBUG => self::ERROR, |
||
243 | ConsoleLogLevel::SUCCESS => self::ERROR, |
||
244 | ]; |
||
245 | |||
246 | /** |
||
247 | * Interpolates context values into the message placeholders. |
||
248 | * |
||
249 | * @author PHP Framework Interoperability Group |
||
250 | * |
||
251 | * @param string $message |
||
252 | * @param array $context |
||
253 | * |
||
254 | * @return string |
||
255 | */ |
||
256 | private function interpolate($message, array $context) |
||
269 | } |
||
270 |