Using verbose in Laravel artisan commands

爷,独闯天下 提交于 2019-12-04 23:03:00

There's the getVerbosity() function in Symfony\Component\Console\Output\OutputInterface and you can use $this->getOutput() to retrieve the output object.

$verbosityLevel = $this->getOutput()->getVerbosity();

You then can compare the level to the constants defined inside OutputInterface. For example:

if($verbosityLevel >= OutputInterface::VERBOSITY_VERBOSE){
    // show verbose messages
}

You can use different verbosities as per the documentation:

https://laravel.com/api/5.6/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 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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!