Using verbose in Laravel artisan commands

Anthony picture Anthony · Dec 22, 2014 · Viewed 8.2k times · Source

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.

Answer

lukasgeiter picture lukasgeiter · Dec 22, 2014

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
}