From be239b9a2240ee56ef1db37939bd62f772cfa115 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 19 Jan 2016 15:07:17 +0100 Subject: [PATCH] Cli: Configure logging properly but also offer customisations --- library/Icinga/Application/Cli.php | 29 +++++++++++++++++++++++++++-- library/Icinga/Cli/Command.php | 4 ++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/library/Icinga/Application/Cli.php b/library/Icinga/Application/Cli.php index 7d2376950..4361910ec 100644 --- a/library/Icinga/Application/Cli.php +++ b/library/Icinga/Application/Cli.php @@ -47,16 +47,41 @@ class Cli extends ApplicationBootstrap ->loadSetupModuleIfNecessary(); } + /** + * {@inheritdoc} + */ protected function setupLogging() { Logger::create( new ConfigObject( array( - 'level' => Logger::INFO, - 'log' => 'stdout', + 'log' => 'stdout' ) ) ); + + return $this; + } + + /** + * {@inheritdoc} + */ + protected function setupLogger() + { + $config = new ConfigObject(); + $config->log = $this->params->shift('log', 'stdout'); + $config->level = $this->params->shift('log-level', Logger::INFO); + if ($config->log === 'file') { + $config->file = $this->params->shiftRequired('log-path'); + } elseif ($config->log === 'syslog') { + $config->application = 'icingacli'; + } + + if ($this->params->shift('verbose', false)) { + $config->level = Logger::DEBUG; + } + + Logger::create($config); return $this; } diff --git a/library/Icinga/Cli/Command.php b/library/Icinga/Cli/Command.php index d0c950a4e..b169a7c16 100644 --- a/library/Icinga/Cli/Command.php +++ b/library/Icinga/Cli/Command.php @@ -21,6 +21,10 @@ abstract class Command */ protected $params; protected $screen; + + /** + * @deprecated Use Logger::debug() directly + */ protected $isVerbose; protected $isDebugging;