NIUCLOUD是一款SaaS管理后台框架多应用插件+云编译。上千名开发者、服务商正在积极拥抱开发者生态。欢迎开发者们免费入驻。一起助力发展! 广告
# 冗长级别 控制台有五个`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 | 可以在命令行中仅以特定的冗长级别来输出信息。比如: ~~~ // ... 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 ); } } ~~~ 有若干语义化的方法可用于测试每一个冗长级别: ~~~ if ($output->isQuiet()) { // ... } if ($output->isVerbose()) { // ... } if ($output->isVeryVerbose()) { // ... } if ($output->isDebug()) { // ... } ~~~ 当使用了`quiet level`(静默级别)时,所有的`output`将被抑制,因为默认的`write()`方法不返回任何真实输出。 > 如果使用了`VERBOSITY_VERBOSE`或以上级别,所有的异常追踪都会被输出。