cli: Polish log handling

* Reintroduced Command::$isDebugging, now without typo
* Removed @deprecated from Command::$isVerbose
* Changed default log level to WARNING
* Adjusted --verbose and --debug to activate log level INFO and DEBUG, respectively
This commit is contained in:
Johannes Meyer 2016-01-21 11:29:28 +01:00
parent 2cf8471a00
commit 9240d1b4e0
3 changed files with 22 additions and 9 deletions

View File

@ -70,16 +70,18 @@ class Cli extends ApplicationBootstrap
{
$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';
}
// TODO: Use shift() instead once Command::$isVerbose has been dropped
if ($this->params->get('verbose', false)) {
$config->level = Logger::INFO;
} elseif ($this->params->get('debug', false)) {
$config->level = Logger::DEBUG;
} else {
$config->level = Logger::WARNING;
}
Logger::create($config);

View File

@ -8,7 +8,6 @@ use Icinga\Util\Translator;
use Icinga\Cli\Params;
use Icinga\Application\Config;
use Icinga\Application\ApplicationBootstrap as App;
use Exception;
use Icinga\Exception\IcingaException;
abstract class Command
@ -23,10 +22,19 @@ abstract class Command
protected $screen;
/**
* @deprecated Use Logger::debug() directly
* Whether the --verbose switch is given and thus the set log level INFO is
*
* @var bool
*/
protected $isVerbose;
/**
* Whether the --debug switch is given and thus the set log level DEBUG is
*
* @var bool
*/
protected $isDebugging;
protected $moduleName;
protected $commandName;
protected $actionName;
@ -47,6 +55,7 @@ abstract class Command
$this->screen = Screen::instance($app);
$this->trace = $this->params->shift('trace', false);
$this->isVerbose = $this->params->shift('verbose', false);
$this->isDebugging = $this->params->shift('debug', false);
if ($initialize) {
$this->init();
}

View File

@ -50,11 +50,13 @@ class Documentation
$d .= ' ' . $module . "\n";
}
$d .= "\nGlobal options:\n\n"
. " --verbose Be verbose\n"
. " --debug Show debug output\n"
. " --help Show help\n"
. " --benchmark Show benchmark summary\n"
. " --watch [s] Refresh output every <s> seconds (default: 5)\n"
. " --log [t] Log to <t>, either stdout, file or syslog (default: stdout)\n"
. " --log-path <f> Which file to log into in case of --log file\n"
. " --verbose Be verbose\n"
. " --debug Show debug output\n"
. " --help Show help\n"
. " --benchmark Show benchmark summary\n"
. " --watch [s] Refresh output every <s> seconds (default: 5)\n"
;
$d .= "\nShow help on a specific command : icingacli help <command>"
. "\nShow help on a specific module : icingacli help <module>"