Skip to content

Instantly share code, notes, and snippets.

@JeffreyWay
Created October 26, 2021 17:16
Show Gist options
  • Save JeffreyWay/f3da30a52f03534e781f9c2c7248bfb7 to your computer and use it in GitHub Desktop.
Save JeffreyWay/f3da30a52f03534e781f9c2c7248bfb7 to your computer and use it in GitHub Desktop.
Example Artisan "tail" command
<?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