From e5c357b5c94c209ebcbff8697e0d091d397e7086 Mon Sep 17 00:00:00 2001 From: Greg Anderson Date: Fri, 1 Apr 2016 15:41:38 -0700 Subject: [PATCH] Use Robo logger to get Robo-styled log output and PSR-3 interpolation. --- composer.lock | 8 ++++---- includes/preflight.inc | 6 +++++- lib/Drush/Log/Logger.php | 30 ++++++++++++++++++++++++------ 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/composer.lock b/composer.lock index 2acb905061..4dff2c94a5 100644 --- a/composer.lock +++ b/composer.lock @@ -13,12 +13,12 @@ "source": { "type": "git", "url": "https://github.com/Codegyre/Robo.git", - "reference": "ceeec44fbf562667e072b9a1f9c2a60a84be22ba" + "reference": "418019213f99be5fd424e2f871c5a5d6cf7bcadd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Codegyre/Robo/zipball/ceeec44fbf562667e072b9a1f9c2a60a84be22ba", - "reference": "ceeec44fbf562667e072b9a1f9c2a60a84be22ba", + "url": "https://api.github.com/repos/Codegyre/Robo/zipball/418019213f99be5fd424e2f871c5a5d6cf7bcadd", + "reference": "418019213f99be5fd424e2f871c5a5d6cf7bcadd", "shasum": "" }, "require": { @@ -67,7 +67,7 @@ } ], "description": "Modern task runner", - "time": "2016-04-01 20:52:57" + "time": "2016-04-01 22:30:29" }, { "name": "consolidation/annotation-command", diff --git a/includes/preflight.inc b/includes/preflight.inc index 6e5dda6954..ce4a8828a9 100644 --- a/includes/preflight.inc +++ b/includes/preflight.inc @@ -242,7 +242,11 @@ function drush_init_dependency_injection_container($input = null, $output = null \Robo\Runner::addInflectors($container); $container->add('container', $container); - $container->share('logger', 'Drush\Log\Logger'); + + $container->share('logStyler', \Robo\Log\RoboLogStyle::class); + $container->share('logger', 'Drush\Log\Logger') + ->withArgument('output') + ->withMethodCall('setLogOutputStyler', ['logStyler']); $container->share('bootstrap.default', 'Drush\Boot\EmptyBoot'); $container->share('bootstrap.drupal6', 'Drush\Boot\DrupalBoot6'); $container->share('bootstrap.drupal7', 'Drush\Boot\DrupalBoot7'); diff --git a/lib/Drush/Log/Logger.php b/lib/Drush/Log/Logger.php index 8aa40b3d03..0591637fb9 100644 --- a/lib/Drush/Log/Logger.php +++ b/lib/Drush/Log/Logger.php @@ -27,8 +27,14 @@ use Drush\Log\LogLevel; use Psr\Log\AbstractLogger; +use Robo\Log\RoboLogger; +use Symfony\Component\Console\Output\OutputInterface; -class Logger extends AbstractLogger { +class Logger extends RoboLogger { + + public function __construct(OutputInterface $output) { + parent::__construct($output); + } public function log($level, $message, array $context = array()) { // Convert to old $entry array for b/c calls @@ -84,6 +90,7 @@ public function log($level, $message, array $context = array()) { return TRUE; } $type_msg = sprintf($green, $level); + $level = LogLevel::NOTICE; break; case LogLevel::NOTICE : $type_msg = sprintf("[%s]", $level); @@ -95,6 +102,7 @@ public function log($level, $message, array $context = array()) { return TRUE; } $type_msg = sprintf("[%s]", $level); + $level = LogLevel::INFO; break; case LogLevel::DEBUG_NOTIFY : $level = LogLevel::DEBUG; // Report 'debug', handle like 'preflight' @@ -104,6 +112,7 @@ public function log($level, $message, array $context = array()) { return TRUE; } $type_msg = sprintf("[%s]", $level); + $level = LogLevel::DEBUG; break; case LogLevel::BOOTSTRAP : case LogLevel::DEBUG : @@ -113,6 +122,7 @@ public function log($level, $message, array $context = array()) { return TRUE; } $type_msg = sprintf("[%s]", $level); + $level = LogLevel::DEBUG; break; } @@ -131,18 +141,26 @@ public function log($level, $message, array $context = array()) { $entry['message'] = $entry['message'] . ' ' . $timer; } +/* + // Drush-styled output + + $message = $this->interpolate( + $entry['message'], + $this->getLogOutputStyler()->style($context) + ); + $width[0] = ($columns - 11); $format = sprintf("%%-%ds%%%ds", $width[0], $width[1]); // Place the status message right aligned with the top line of the error message. - $message = wordwrap($entry['message'], $width[0]); + $message = wordwrap($message, $width[0]); $lines = explode("\n", $message); $lines[0] = sprintf($format, $lines[0], $type_msg); $message = implode("\n", $lines); - drush_print($message, 0, STDERR); - + $this->getErrorStreamWrapper()->writeln($message); +*/ + // Robo-styled output + parent::log($level, $message, $context); } - - }