From 21d5f4954fee6f12019500bbaf73b12ce0346a0f Mon Sep 17 00:00:00 2001 From: Dan Cryer Date: Wed, 27 Apr 2016 14:56:52 +0100 Subject: [PATCH] Adding a debug mode to the worker so you can see what commands are being run. --- PHPCI/Command/WorkerCommand.php | 9 ++++++++- PHPCI/Helper/BaseCommandExecutor.php | 4 ++++ PHPCI/Logging/BuildLogger.php | 11 ++++++++++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/PHPCI/Command/WorkerCommand.php b/PHPCI/Command/WorkerCommand.php index 49685656..5ceb6a84 100644 --- a/PHPCI/Command/WorkerCommand.php +++ b/PHPCI/Command/WorkerCommand.php @@ -50,7 +50,8 @@ class WorkerCommand extends Command { $this ->setName('phpci:worker') - ->setDescription('Runs the PHPCI build worker.'); + ->setDescription('Runs the PHPCI build worker.') + ->addOption('debug', null, null, 'Run PHPCI in Debug Mode'); } protected function execute(InputInterface $input, OutputInterface $output) @@ -65,6 +66,12 @@ class WorkerCommand extends Command ); } + // Allow PHPCI to run in "debug mode" + if ($input->hasOption('debug') && $input->getOption('debug')) { + $output->writeln('Debug mode enabled.'); + define('PHPCI_DEBUG_MODE', true); + } + $config = Config::getInstance()->get('phpci.worker', []); if (empty($config['host']) || empty($config['queue'])) { diff --git a/PHPCI/Helper/BaseCommandExecutor.php b/PHPCI/Helper/BaseCommandExecutor.php index bd948834..ddfa78df 100644 --- a/PHPCI/Helper/BaseCommandExecutor.php +++ b/PHPCI/Helper/BaseCommandExecutor.php @@ -90,6 +90,10 @@ abstract class BaseCommandExecutor implements CommandExecutor $pipes = array(); + if (defined('PHPCI_DEBUG_MODE')) { + $this->logger->logDebug($command); + } + $process = proc_open($command, $descriptorSpec, $pipes, $this->buildPath, null); if (is_resource($process)) { diff --git a/PHPCI/Logging/BuildLogger.php b/PHPCI/Logging/BuildLogger.php index 73f3b464..cae5ff22 100644 --- a/PHPCI/Logging/BuildLogger.php +++ b/PHPCI/Logging/BuildLogger.php @@ -67,7 +67,7 @@ class BuildLogger implements LoggerAwareInterface } } - /** + /** * Add a success-coloured message to the log. * @param string */ @@ -98,6 +98,15 @@ class BuildLogger implements LoggerAwareInterface ); } + /** + * Add a debug message to the log. + * @param string + */ + public function logDebug($message) + { + $this->log("\033[0;33m" . $message . "\033[0m"); + } + /** * Sets a logger instance on the object *