diff --git a/.gitignore b/.gitignore index 2f2601ea..620cd6ce 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,5 @@ config.php .buildpath .htaccess PHPCI/config.yml -cache \ No newline at end of file +cache +/loggerconfig.php \ No newline at end of file diff --git a/PHPCI/Helper/LoggerConfig.php b/PHPCI/Helper/LoggerConfig.php new file mode 100644 index 00000000..958f76eb --- /dev/null +++ b/PHPCI/Helper/LoggerConfig.php @@ -0,0 +1,51 @@ +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 = array(); + + // They key is expected to either be an array or + // a callable function that returns an array + if (isset($this->config[$name])) { + if (is_callable($this->config[$name])) { + $handlers = call_user_func($this->config[$name]); + } + elseif(is_array($this->config[$name])) { + $handlers = $this->config[$name]; + } + } + + return new Logger($name, $handlers); + } + +} \ No newline at end of file diff --git a/console b/console index 3a56e7cd..7525b054 100755 --- a/console +++ b/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 GenerateCommand); $application->add(new DaemonCommand); + $application->run(); diff --git a/loggerconfig.php.example b/loggerconfig.php.example new file mode 100644 index 00000000..a5daccfe --- /dev/null +++ b/loggerconfig.php.example @@ -0,0 +1,9 @@ + function() { + return array( + new \Monolog\Handler\StreamHandler('path/to/logs/errors', \Monolog\Logger::ERROR), + new \Monolog\Handler\RotatingFileHandler('path/to/logs/everything',3, \Monolog\Logger::INFO), + ); + } +); \ No newline at end of file