|
33 | 33 |
|
34 | 34 | class Logger extends RoboLogger |
35 | 35 | { |
| 36 | + /** |
| 37 | + * Array of logs. For use by backend responses. |
| 38 | + * |
| 39 | + * @var array |
| 40 | + * |
| 41 | + * @deprecated |
| 42 | + */ |
| 43 | + protected $logs = []; |
| 44 | + |
| 45 | + /** |
| 46 | + * Array of error logs. For use by backend responses. |
| 47 | + * |
| 48 | + * @var array |
| 49 | + * |
| 50 | + * @deprecated |
| 51 | + */ |
| 52 | + protected $logs_error = []; |
36 | 53 |
|
37 | 54 | public function __construct(OutputInterface $output) |
38 | 55 | { |
39 | 56 | parent::__construct($output); |
40 | 57 | } |
41 | 58 |
|
| 59 | + /** |
| 60 | + * Get an array of logs for the current request. |
| 61 | + * |
| 62 | + * @return array |
| 63 | + * |
| 64 | + * @deprecated Used by drush_backend_output(). |
| 65 | + */ |
| 66 | + public function getLogs() |
| 67 | + { |
| 68 | + return $this->logs; |
| 69 | + } |
| 70 | + |
| 71 | + /** |
| 72 | + * Get an array of error logs for the current request. |
| 73 | + * |
| 74 | + * @return array |
| 75 | + * |
| 76 | + * @deprecated Used by drush_backend_output(). |
| 77 | + */ |
| 78 | + public function getErrorLogs() |
| 79 | + { |
| 80 | + return $this->logs_error; |
| 81 | + } |
| 82 | + |
| 83 | + /** |
| 84 | + * Empty log collections. |
| 85 | + * |
| 86 | + * @deprecated |
| 87 | + */ |
| 88 | + public function clearLogs() |
| 89 | + { |
| 90 | + $this->logs_error = $this->logs = []; |
| 91 | + } |
| 92 | + |
42 | 93 | public function log($level, $message, array $context = []) |
43 | 94 | { |
44 | | - // Convert to old $entry array for b/c calls |
45 | | - $entry = $context + [ |
46 | | - 'type' => $level, |
47 | | - 'message' => StringUtils::interpolate($message, $context), |
48 | | - 'timestamp' => microtime(true), |
49 | | - 'memory' => memory_get_usage(), |
50 | | - ]; |
| 95 | + $entry = $this->buildEntry($level, $message, $context); |
| 96 | + |
| 97 | + if (Drush::backend()) { |
| 98 | + $this->logs[] = $entry; |
| 99 | + } |
51 | 100 |
|
52 | | - // Drush\Log\Logger should take over all of the responsibilities |
53 | | - // of drush_log, including caching the log messages and sending |
54 | | - // log messages along to backend invoke. |
55 | | - // TODO: move these implementations inside this class. |
56 | | - $log =& drush_get_context('DRUSH_LOG', []); |
57 | | - $log[] = $entry; |
58 | 101 | if ($level != LogLevel::DEBUG_NOTIFY) { |
59 | 102 | drush_backend_packet('log', $entry); |
60 | 103 | } |
@@ -151,33 +194,33 @@ public function log($level, $message, array $context = []) |
151 | 194 | $message = $message . ' ' . $timer; |
152 | 195 | } |
153 | 196 |
|
154 | | -/* |
155 | | - // Drush-styled output |
156 | | -
|
157 | | - $message = $this->interpolate( |
158 | | - $message, |
159 | | - $this->getLogOutputStyler()->style($context) |
160 | | - ); |
161 | | -
|
162 | | - $width[0] = ($columns - 11); |
163 | | -
|
164 | | - $format = sprintf("%%-%ds%%%ds", $width[0], $width[1]); |
165 | | -
|
166 | | - // Place the status message right aligned with the top line of the error message. |
167 | | - $message = wordwrap($message, $width[0]); |
168 | | - $lines = explode("\n", $message); |
169 | | - $lines[0] = sprintf($format, $lines[0], $type_msg); |
170 | | - $message = implode("\n", $lines); |
171 | | - $this->getErrorStreamWrapper()->writeln($message); |
172 | | -*/ |
173 | 197 | // Robo-styled output |
174 | 198 | parent::log($level, $message, $context); |
175 | 199 | } |
176 | 200 |
|
177 | 201 | public function error($message, array $context = []) |
178 | 202 | { |
179 | | - $error_log =& drush_get_context('DRUSH_ERROR_LOG', []); |
180 | | - $error_log[$message][] = $message; |
| 203 | + if (Drush::backend()) { |
| 204 | + $this->logs_error[] = $this->buildEntry(LogLevel::ERROR, $message, $context); |
| 205 | + } |
181 | 206 | parent::error($message, $context); |
182 | 207 | } |
| 208 | + |
| 209 | + /** |
| 210 | + * @param $level |
| 211 | + * @param $message |
| 212 | + * @param array $context |
| 213 | + * @return array |
| 214 | + */ |
| 215 | + protected function buildEntry($level, $message, array $context) |
| 216 | + { |
| 217 | + // Convert to old $entry array for b/c calls |
| 218 | + $entry = $context + [ |
| 219 | + 'type' => $level, |
| 220 | + 'message' => StringUtils::interpolate($message, $context), |
| 221 | + 'timestamp' => microtime(true), |
| 222 | + 'memory' => memory_get_usage(), |
| 223 | + ]; |
| 224 | + return $entry; |
| 225 | + } |
183 | 226 | } |
0 commit comments