Created
October 26, 2021 17:16
-
-
Save JeffreyWay/f3da30a52f03534e781f9c2c7248bfb7 to your computer and use it in GitHub Desktop.
Example Artisan "tail" command
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Illuminate\Foundation\Inspiring; | |
use Illuminate\Support\Facades\Artisan; | |
use Symfony\Component\Process\Process; | |
/* | |
|-------------------------------------------------------------------------- | |
| Console Routes | |
|-------------------------------------------------------------------------- | |
| | |
| This file is where you may define all of your Closure based console | |
| commands. Each Closure is bound to a command instance allowing a | |
| simple approach to interacting with each command's IO methods. | |
| | |
*/ | |
Artisan::command( | |
'tail {file=storage/logs/laravel.log : A path to the file being tailed. } | |
{--only= : Grep the output for a specific string. } | |
', | |
function () { | |
$command = 'tail -f "$FILE" | grep "$ONLY"'; | |
Process::fromShellCommandline($command) | |
->setTty(true) | |
->setTimeout(null) | |
->run(null, [ | |
'FILE' => $this->argument('file'), | |
'ONLY' => $this->option('only'), | |
]); | |
})->purpose('Tail the app log file.'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment