Merge HEAD, branch 'master' of https://github.com/Block8/PHPCI into plugin-builder
This commit is contained in:
commit
a56df8ed87
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -8,4 +8,5 @@ config.php
|
|||
.buildpath
|
||||
.htaccess
|
||||
PHPCI/config.yml
|
||||
cache
|
||||
cache
|
||||
/loggerconfig.php
|
|
@ -252,7 +252,7 @@ class Builder implements LoggerAwareInterface
|
|||
|
||||
// The build is added to the context so the logger can use
|
||||
// details from it if required.
|
||||
$context['build'] = $this;
|
||||
$context['build'] = $this->build;
|
||||
|
||||
foreach ($message as $item) {
|
||||
$this->logger->log($level, $item, $context);
|
||||
|
|
|
@ -10,8 +10,10 @@
|
|||
|
||||
namespace PHPCI\Command;
|
||||
|
||||
use Monolog\Logger;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputDefinition;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
@ -27,6 +29,17 @@ use PHPCI\BuildFactory;
|
|||
*/
|
||||
class DaemonCommand extends Command
|
||||
{
|
||||
/**
|
||||
* @var \Monolog\Logger
|
||||
*/
|
||||
protected $logger;
|
||||
|
||||
public function __construct(Logger $logger, $name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
|
@ -68,12 +81,14 @@ class DaemonCommand extends Command
|
|||
|
||||
if (file_exists(PHPCI_DIR.'/daemon/daemon.pid')) {
|
||||
echo "Already started\n";
|
||||
$this->logger->warning("Daemon already started");
|
||||
return "alreadystarted";
|
||||
}
|
||||
|
||||
$logfile = PHPCI_DIR."/daemon/daemon.log";
|
||||
$cmd = "nohup %s/daemonise phpci:daemonise > %s 2>&1 &";
|
||||
$command = sprintf($cmd, PHPCI_DIR, $logfile);
|
||||
$this->logger->info("Daemon started");
|
||||
exec($command);
|
||||
}
|
||||
|
||||
|
@ -82,12 +97,14 @@ class DaemonCommand extends Command
|
|||
|
||||
if (!file_exists(PHPCI_DIR.'/daemon/daemon.pid')) {
|
||||
echo "Not started\n";
|
||||
$this->logger->warning("Can't stop daemon as not started");
|
||||
return "notstarted";
|
||||
}
|
||||
|
||||
$cmd = "kill $(cat %s/daemon/daemon.pid)";
|
||||
$command = sprintf($cmd, PHPCI_DIR);
|
||||
exec($command);
|
||||
$this->logger->info("Daemon stopped");
|
||||
unlink(PHPCI_DIR.'/daemon/daemon.pid');
|
||||
}
|
||||
|
||||
|
@ -110,13 +127,4 @@ class DaemonCommand extends Command
|
|||
echo "Not running\n";
|
||||
return "notrunning";
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when log entries are made in Builder / the plugins.
|
||||
* @see \PHPCI\Builder::log()
|
||||
*/
|
||||
public function logCallback($log)
|
||||
{
|
||||
$this->output->writeln($log);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,6 +36,22 @@ class RunCommand extends Command
|
|||
*/
|
||||
protected $output;
|
||||
|
||||
/**
|
||||
* @var Logger
|
||||
*/
|
||||
protected $logger;
|
||||
|
||||
/**
|
||||
* @param \Monolog\Logger $logger
|
||||
* @param string $name
|
||||
*/
|
||||
public function __construct(Logger $logger, $name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
|
@ -50,21 +66,22 @@ class RunCommand extends Command
|
|||
{
|
||||
$this->output = $output;
|
||||
|
||||
$logger = new Logger("BuildLog");
|
||||
|
||||
$store = Factory::getStore('Build');
|
||||
$result = $store->getByStatus(0);
|
||||
$builds = 0;
|
||||
|
||||
// For verbose mode we want to output all informational and above
|
||||
// messages to the symphony output interface.
|
||||
if ($input->getOption('verbose')) {
|
||||
$logger->pushHandler(
|
||||
$this->logger->pushHandler(
|
||||
new OutputLogHandler($this->output, Logger::INFO)
|
||||
);
|
||||
}
|
||||
|
||||
$logger->pushProcessor(new LoggedBuildContextTidier());
|
||||
$this->logger->pushProcessor(new LoggedBuildContextTidier());
|
||||
|
||||
$this->logger->addInfo("Finding builds to process");
|
||||
$store = Factory::getStore('Build');
|
||||
$result = $store->getByStatus(0);
|
||||
$this->logger->addInfo(sprintf("Found %d builds", count($result['items'])));
|
||||
|
||||
$builds = 0;
|
||||
|
||||
foreach ($result['items'] as $build) {
|
||||
$builds++;
|
||||
|
@ -74,16 +91,18 @@ class RunCommand extends Command
|
|||
// Logging relevant to this build should be stored
|
||||
// against the build itself.
|
||||
$buildDbLog = new BuildDBLogHandler($build, Logger::INFO);
|
||||
$logger->pushHandler($buildDbLog);
|
||||
$this->logger->pushHandler($buildDbLog);
|
||||
|
||||
$builder = new Builder($build, $logger);
|
||||
$builder = new Builder($build, $this->logger);
|
||||
$builder->execute();
|
||||
|
||||
// After execution we no longer want to record the information
|
||||
// back to this specific build so the handler should be removed.
|
||||
$logger->popHandler($buildDbLog);
|
||||
$this->logger->popHandler($buildDbLog);
|
||||
}
|
||||
|
||||
$this->logger->addInfo("Finished processing builds");
|
||||
|
||||
return $builds;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,8 +9,10 @@
|
|||
|
||||
namespace PHPCI\Command;
|
||||
|
||||
use Monolog\Logger;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputDefinition;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
@ -23,6 +25,17 @@ use Symfony\Component\Console\Output\OutputInterface;
|
|||
*/
|
||||
class UpdateCommand extends Command
|
||||
{
|
||||
/**
|
||||
* @var \Monolog\Logger
|
||||
*/
|
||||
protected $logger;
|
||||
|
||||
public function __construct(Logger $logger, $name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
|
|
|
@ -2,9 +2,10 @@
|
|||
|
||||
namespace PHPCI\Helper;
|
||||
|
||||
use PHPCI\Model\Build;
|
||||
|
||||
class LoggedBuildContextTidier{
|
||||
|
||||
class LoggedBuildContextTidier
|
||||
{
|
||||
function __invoke()
|
||||
{
|
||||
return $this->tidyLoggedBuildContext(func_get_arg(0));
|
||||
|
|
58
PHPCI/Helper/LoggerConfig.php
Normal file
58
PHPCI/Helper/LoggerConfig.php
Normal file
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace PHPCI\Helper;
|
||||
|
||||
|
||||
use Monolog\Logger;
|
||||
|
||||
class LoggerConfig {
|
||||
|
||||
const KEY_AlwaysLoaded = "_";
|
||||
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* The file specified is expected to return an array. Where each key
|
||||
* is the name of a logger. The value of each key should be an array or
|
||||
* a function that returns an array of LogHandlers.
|
||||
* @param $logConfigFilePath
|
||||
*/
|
||||
function __construct($logConfigFilePath) {
|
||||
if (file_exists($logConfigFilePath)) {
|
||||
$this->config = require_once($logConfigFilePath);
|
||||
}
|
||||
else {
|
||||
$this->config = array();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an instance of Monolog with all configured handlers
|
||||
* added. The Monolog instance will be given $name.
|
||||
* @param $name
|
||||
* @return Logger
|
||||
*/
|
||||
public function GetFor($name) {
|
||||
$handlers = $this->getHandlers(self::KEY_AlwaysLoaded);
|
||||
$handlers = array_merge($handlers, $this->getHandlers($name));
|
||||
return new Logger($name, $handlers);
|
||||
}
|
||||
|
||||
protected function getHandlers($key) {
|
||||
$handlers = array();
|
||||
|
||||
// They key is expected to either be an array or
|
||||
// a callable function that returns an array
|
||||
if (isset($this->config[$key])) {
|
||||
if (is_callable($this->config[$key])) {
|
||||
$handlers = call_user_func($this->config[$key]);
|
||||
}
|
||||
elseif(is_array($this->config[$key])) {
|
||||
$handlers = $this->config[$key];
|
||||
}
|
||||
}
|
||||
return $handlers;
|
||||
}
|
||||
|
||||
}
|
10
console
10
console
|
@ -19,10 +19,14 @@ use PHPCI\Command\InstallCommand;
|
|||
use PHPCI\Command\DaemonCommand;
|
||||
use Symfony\Component\Console\Application;
|
||||
|
||||
$loggerConfig = new \PHPCI\Helper\LoggerConfig(__DIR__ . "/loggerconfig.php");
|
||||
|
||||
$application = new Application();
|
||||
$application->add(new RunCommand);
|
||||
|
||||
$application->add(new RunCommand($loggerConfig->GetFor('RunCommand')));
|
||||
$application->add(new InstallCommand);
|
||||
$application->add(new UpdateCommand);
|
||||
$application->add(new UpdateCommand($loggerConfig->GetFor('UpdateCommand')));
|
||||
$application->add(new GenerateCommand);
|
||||
$application->add(new DaemonCommand);
|
||||
$application->add(new DaemonCommand($loggerConfig->GetFor('DaemonCommand')));
|
||||
|
||||
$application->run();
|
||||
|
|
16
loggerconfig.php.example
Normal file
16
loggerconfig.php.example
Normal file
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
return array(
|
||||
/** Loggers attached to every command */
|
||||
"_" => function() {
|
||||
return array(
|
||||
new \Monolog\Handler\StreamHandler('c:\temp\errors.log', \Monolog\Logger::ERROR),
|
||||
);
|
||||
},
|
||||
|
||||
/** Loggers for the RunCommand */
|
||||
'RunCommand' => function() {
|
||||
return array(
|
||||
new \Monolog\Handler\RotatingFileHandler('c:\temp\everything',3, \Monolog\Logger::INFO),
|
||||
);
|
||||
}
|
||||
);
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
require_once(dirname(__FILE__) . '/../vars.php');
|
||||
require_once(dirname(__FILE__) . '/../bootstrap.php');
|
||||
|
||||
$installStage = 'start';
|
||||
$formAction = '';
|
||||
|
|
Loading…
Reference in a new issue