Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions includes/backend.inc
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ function drush_backend_output() {
}

$data['error_status'] = Runtime::exitCode();
$data['log'] = drush_get_log(); // Append logging information
$data['log'] = Drush::logger()->getLogs(); // Append logging information
// The error log is a more specific version of the log, and may be used by calling
// scripts to check for specific errors that have occurred.
$data['error_log'] = drush_get_error_log();
$data['error_log'] = Drush::logger()->getErrorLogs();
// If there is a @self record, then include it in the result
$self_record = drush_sitealias_get_record('@self');
if (!empty($self_record)) {
Expand Down
78 changes: 63 additions & 15 deletions src/Log/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,59 @@

class Logger extends RoboLogger
{
/**
* Array of logs. For use by backend responses.
*
* @var array
*
* @deprecated
*/
protected $logs = [];

/**
* Array of error logs. For use by backend responses.
*
* @var array
*
* @deprecated
*/
protected $logs_error = [];

public function __construct(OutputInterface $output)
{
parent::__construct($output);
}

/**
* Get an array of logs for the current request.
*
* @return array
*
* @deprecated Used by drush_backend_output().
*/
public function getLogs()
{
return $this->logs;
}

/**
* Get an array of error logs for the current request.
*
* @return array
*
* @deprecated Used by drush_backend_output().
*/
public function getErrorLogs()
{
return $this->logs_error;
}

public function log($level, $message, array $context = [])
{
// Convert to old $entry array for b/c calls
$entry = $context + [
'type' => $level,
'message' => StringUtils::interpolate($message, $context),
'timestamp' => microtime(true),
'memory' => memory_get_usage(),
];
$entry = $this->buildEntry($level, $message, $context);

$this->logs[] = $entry;

// Drush\Log\Logger should take over all of the responsibilities
// of drush_log, including caching the log messages and sending
// log messages along to backend invoke.
// TODO: move these implementations inside this class.
$log =& drush_get_context('DRUSH_LOG', []);
$log[] = $entry;
if ($level != LogLevel::DEBUG_NOTIFY) {
drush_backend_packet('log', $entry);
}
Expand Down Expand Up @@ -176,8 +207,25 @@ public function log($level, $message, array $context = [])

public function error($message, array $context = [])
{
$error_log =& drush_get_context('DRUSH_ERROR_LOG', []);
$error_log[$message][] = $message;
$this->logs_error[] = $this->buildEntry(LogLevel::ERROR, $message, $context);
parent::error($message, $context);
}

/**
* @param $level
* @param $message
* @param array $context
* @return array
*/
protected function buildEntry($level, $message, array $context)
{
// Convert to old $entry array for b/c calls
$entry = $context + [
'type' => $level,
'message' => StringUtils::interpolate($message, $context),
'timestamp' => microtime(true),
'memory' => memory_get_usage(),
];
return $entry;
}
}