在 Laravel 工匠命令中使用详细
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27611213/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using verbose in Laravel artisan commands
提问by Anthony
Is there a way to detect what verbosity level the user has specified when creating a custom artisan command? I don't see anything about it in the docs.
有没有办法检测用户在创建自定义工匠命令时指定的详细级别?我在文档中没有看到任何关于它的内容。
回答by lukasgeiter
There's the getVerbosity()
function in Symfony\Component\Console\Output\OutputInterface
and you can use $this->getOutput()
to retrieve the output object.
里面有getVerbosity()
函数,Symfony\Component\Console\Output\OutputInterface
你可以用它$this->getOutput()
来检索输出对象。
$verbosityLevel = $this->getOutput()->getVerbosity();
You then can compare the level to the constants defined inside OutputInterface
. For example:
然后,您可以将级别与内部定义的常量进行比较OutputInterface
。例如:
if($verbosityLevel >= OutputInterface::VERBOSITY_VERBOSE){
// show verbose messages
}
回答by Greg Robson
You can use different verbosities as per the documentation:
您可以根据文档使用不同的详细程度:
https://laravel.com/api/6.x/Illuminate/Console/OutputStyle.html#method_isQuiet
https://laravel.com/api/6.x/Illuminate/Console/OutputStyle.html#method_isQuiet
isQuiet() - no verbosity is set (no option set)
isVerbose() - if the level is quiet or verbose (-v)
isVeryVerbose() - if the level is very verbose, verbose or quiet (-vv)
isDebug() - if the level is debug, very verbose, verbose or quiet (-vvv)
e.g. In your command $this->getOutput()->isQuiet()
例如在你的命令中 $this->getOutput()->isQuiet()
This also affects writeLn()
. If you were to write $this->line('Serious message', null, 'vv');
The message would appear for -vv
and -vvv
options, but not -v
and silent modes as it is "too detailed" for those levels of logging.
这也会影响writeLn()
. 如果您要编写$this->line('Serious message', null, 'vv');
消息将出现在-vv
和-vvv
选项中,但不会出现-v
和静默模式,因为它对于这些级别的日志记录来说“太详细”了。