Skip to content

Commit

Permalink
Merge pull request #54 from marchampson/feature/grep-option
Browse files Browse the repository at this point in the history
Added grep feature and updated readme
  • Loading branch information
freekmurze authored Feb 23, 2020
2 parents e2fe5b4 + 3650d20 commit 6be684e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 5 additions & 2 deletions src/TailCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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;
}
}

0 comments on commit 6be684e

Please sign in to comment.