Created
August 19, 2018 00:06
-
-
Save jakebathman/a1122071428c78942c6bed4cade18dd6 to your computer and use it in GitHub Desktop.
Tail Laravel logs and filter out the stack traces
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
tail -f -n 450 storage/logs/laravel*.log \ | |
| grep -i -E \ | |
"^\[\d{4}\-\d{2}\-\d{2} \d{2}:\d{2}:\d{2}\]|Next [\w\W]+?\:" \ | |
--color |
+1 Thanks a lot!
Awesome. Thanks for this
A bit modified for faster commands:
function log.l {
echo "Printing contents of Laravel Log File"
echo "Press Ctrl + C to exit"
echo "Tip: Type 'log.c' to clear contents of Laravel Log File"
tail -f -n 450 storage/logs/laravel*.log \
| grep -i -E \
"^\[\d{4}\-\d{2}\-\d{2} \d{2}:\d{2}:\d{2}\]|Next [\w\W]+?\:" \
--color
}
function log.c {
echo "Clearing contents of Laravel Log File"
echo > storage/logs/laravel*.log
}
Thought I'd try sticking this into a composer script, but can't get any output.
I have scripts/tail_laravel_log.sh
:
tail -f -n 450 storage/logs/laravel*.log \
| grep -i -E \
"^\[\d{4}\-\d{2}\-\d{2} \d{2}:\d{2}:\d{2}\]|Next [\w\W]+?\:"
And then in composer.json:
"scripts": {
"logtail": [
"./scripts/tail_laravel_log.sh"
]
}
Running ./scripts/tail_laravel_log.sh
works like a charm, but running composer logtail
produces no output. Any ideas?
on opening a new tab it will check for the file Laravel log file and will throw an error that file doesn't exist, which is annoying
so I guess it would be better to check if the directory actually exists first before reading/writing from the file
NOTE: this scenario will happen if you adding these two functions two your .zshrc file or .bashrc file, so I had to add an extra condition.
function log_laravel {
DIRECTORY=storage/logs/
if [[ -d "$DIRECTORY" ]]; then
echo "Printing contents of Laravel Log File"
tail -f -n 450 storage/logs/laravel*.log \
| grep -i -E \
"^\[\d{4}\-\d{2}\-\d{2} \d{2}:\d{2}:\d{2}\]|Next [\w\W]+?\:" \
--color
fi
}
function log_clear {
DIRECTORY=storage/logs/
if [[ -d "$DIRECTORY" ]]; then
echo > storage/logs/laravel*.log
fi
}
hope this helps.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks 👍