From a3099c82f2de6569ddc19db8945406f6e1e9fc67 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Tue, 22 Oct 2013 14:15:11 +0000 Subject: [PATCH] CLI parameters override log config, writer is STDERR --- library/Icinga/Application/Cli.php | 35 +++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/library/Icinga/Application/Cli.php b/library/Icinga/Application/Cli.php index ed8674c4c..b6fa033a9 100644 --- a/library/Icinga/Application/Cli.php +++ b/library/Icinga/Application/Cli.php @@ -30,14 +30,34 @@ class Cli extends ApplicationBootstrap protected $cliLoader; + protected $verbose; + + protected $debug; + protected function bootstrap() { $this->assertRunningOnCli(); - return $this->setupConfig() - ->setupErrorHandling() - ->setupResourceFactory() - ->setupModules() - ->parseParams(); + $this->setupConfig() + ->parseBasicParams() + ->fixLoggingConfig() + ->setupErrorHandling() + ->setupResourceFactory() + ->setupModules() + ; + } + + protected function fixLoggingConfig() + { + $conf = & $this->getConfig()->logging; + if ($conf->type === 'stream') { + $conf->verbose = $this->verbose; + $conf->target = 'php://stderr'; + } + if ($conf->debug && $conf->debug->type === 'stream') { + $conf->debug->target = 'php://stderr'; + $conf->debug->enable = $this->debug; + } + return $this; } public function cliLoader() @@ -76,7 +96,7 @@ class Cli extends ApplicationBootstrap return $this->moduleManager; } - protected function parseParams() + protected function parseBasicParams() { $this->params = Params::parse(); if ($this->params->shift('help')) { @@ -90,6 +110,9 @@ class Cli extends ApplicationBootstrap $this->watchTimeout = (int) $watch; } + $this->debug = (int) $this->params->get('debug'); + $this->verbose = (int) $this->params->get('verbose'); + $this->showBenchmark = (bool) $this->params->shift('benchmark'); return $this; }