diff --git a/README.md b/README.md index e3a263e..f197d7e 100755 --- a/README.md +++ b/README.md @@ -86,6 +86,12 @@ This can be useful if you're only interested in the last log entry when debuggin php artisan tail --clear ``` +Should you wish to filter the log to return only certain keywords then you can also use the grep feature. + +```bash +php artisan tail --grep="keywords" +``` + ### Tailing remote logs To tail remote logs, you must first specify values for `host`, `user` and `log_directory` keys of an environment in the `tail` config file. diff --git a/src/TailCommand.php b/src/TailCommand.php index d9d9019..eb8c095 100644 --- a/src/TailCommand.php +++ b/src/TailCommand.php @@ -11,7 +11,8 @@ class TailCommand extends Command { protected $signature = 'tail {environment?} {--lines=0 : Output the last number of lines} - {--clear : Clear the terminal screen}'; + {--clear : Clear the terminal screen} + {--grep="" : Grep specified string}'; protected $description = 'Tail the latest logfile'; @@ -79,6 +80,8 @@ protected function getEnvironmentConfiguration(string $environment): array public function getTailCommand(): string { - return 'tail -f -n '.$this->option('lines').' "`ls -t | head -1`"'; + $grep = ($this->option('grep')) ? ' | grep "' . $this->option('grep').'"' : ''; + + return 'tail -f -n '.$this->option('lines').' "`ls -t | head -1`"' . $grep; } }