laravellaravel-artisanverbosity

Using verbose in Laravel artisan commands


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.


Solution

  • 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
    }