# 冗長級別
控制臺有五個 `Verbosity Levels`(冗長級別),它們被定義在 `\think\console\Output`:
|模式|說明|控制臺參數|
|:---|:----|:------|
|`Output::VERBOSITY_QUIET`|不要輸出任何信息|-q or --quiet|
|`Output::VERBOSITY_NORMAL`|此為默認的冗長級別|(none)|
|`Output::VERBOSITY_VERBOSE`|冗長程度有所增加的信息|-v|
|`Output::VERBOSITY_VERY_VERBOSE`|加大非基本信息數量|-vv|
|`Output::VERBOSITY_DEBUG`|調試信息|-vvv|
可以在命令行中僅以特定的冗長級別來輸出信息。比如:
```php
// ...
class CreateUser extends Command
{
// ...
public function execute(Input $input, Output $output)
{
$user = new User(...);
$output->writeln(array(
'Username: '.$input->getArgument('username'),
'Password: '.$input->getArgument('password'),
));
// user 類僅當使用了 vv 級別時才會輸出
if ($output->getVerbosity() >= Output::VERBOSITY_VERBOSE) {
$output->writeln('User class: '.get_class($user));
}
// 你也可以把冗長級別傳到 writeln() 中
$output->writeln(
'Will only be printed in verbose mode or higher', // 僅當v級或以上才會輸出
Output::VERBOSITY_VERBOSE
);
}
}
```
有若干語義化的方法可用于測試每一個冗長級別:
```php
if ($output->isQuiet()) {
// ...
}
if ($output->isVerbose()) {
// ...
}
if ($output->isVeryVerbose()) {
// ...
}
if ($output->isDebug()) {
// ...
}
```
當使用了 `quiet level`(靜默級別)時,所有的 `output` 將被抑制,因為默認的 `write()` 方法不返回任何真實輸出。
> 如果使用了 `VERBOSITY_VERBOSE` 或以上級別,所有的異常追蹤都會被輸出。