Skip to content

Commit

Permalink
Use Robo logger to get Robo-styled log output and PSR-3 interpolation.
Browse files Browse the repository at this point in the history
  • Loading branch information
greg-1-anderson committed Apr 1, 2016
1 parent 54f2a67 commit e5c357b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 11 deletions.
8 changes: 4 additions & 4 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion includes/preflight.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
30 changes: 24 additions & 6 deletions lib/Drush/Log/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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'
Expand All @@ -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 :
Expand All @@ -113,6 +122,7 @@ public function log($level, $message, array $context = array()) {
return TRUE;
}
$type_msg = sprintf("[%s]", $level);
$level = LogLevel::DEBUG;
break;
}

Expand All @@ -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);
}


}

0 comments on commit e5c357b

Please sign in to comment.