Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using verbose in Laravel artisan commands

Tags:

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.

like image 799
Anthony Avatar asked Dec 22 '14 22:12

Anthony


People also ask

Which artisan command makes another artisan command?

To call another Artisan command and save its output you should use $this->call() from your command.

What is artisan command in Laravel?

Artisan is the name of the command-line interface included with Laravel. It provides a number of helpful commands for your use while developing your application.

What is php artisan optimize?

php artisan optimize creates a compiled file of commonly used classes in other to reduce the amount of files that must be included on each request. After running the command, all commonly used classes are compiled and then saved to this file directory: bootstrap/cache/compiled.


1 Answers

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
}
like image 189
lukasgeiter Avatar answered Sep 21 '22 15:09

lukasgeiter