Using verbose in Laravel artisan commands
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/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 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.