Follow your (Laravel) Logfiles on your bash with colored output
I am a big fan of my Linux bash, and maybe you are as well.
I guess we all agree, that the most simple way of watching a logfile is
a simple
tail -f storage/log/laravel.log
Because I already pimped by bash with other nice tools to get more colors,
like powerline-go or simple hacks like using pandoc to watch readme files, I finally got sick of these boring gray lines when watching my logfiles.
So I looked around and very quickly found a super simple easy solution.
I am talking about grc, it’s a “Generic Colouriser” and it does what it says, it brings color into your life ;)
It’s very powerful but I will focus on the topic and will show you how easy it is to paint our laravel.log file.
# use the latest version when reading this
wget https://github.com/garabik/grc/archive/refs/tags/v1.13.tar.gz
tar xfv v1.13.tar.gz
cd grc-1.13/
sudo bash install.sh
With that, you have installed grc, and you can try if it´s working:
grc tail -f storage/log/laravel.log
Are you missing colors? That´s okay, because grc does not know how to handle this kind of logfile, but it only takes a few lines to fix this.
Create a new file ~/.grc/grc.conf and put this in:
regexp=\[\d+-\d+-\d+\s\d+:\d+:\d+\]
colour=green
count=once
--
regexp=local.INFO
colour=yellow
count=once
now you can do:
grc -c ~/.grc/grc.conf tail -f storage/log/laravel.log
and you should see this:
because we are lazy, we make life a little easier for ourselves and put this alias into our ~/.bashrc
ctail() { grc -c ~/.grc/grc.conf tail -f "$1"; }
and now we are able to:
ctail storage/log/laravel.log
The next step of course is to create regexes for “local.WARN” or “local.ERROR” and whatever you want. Because you can work with a regex,
you can colorize everything as you want ;)
I hope, I was able to bring some color into your life, and if this was some kind useful to you, feel free to clap or follow me. THANK YOU!