Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I see the colored log using tail or less?

enter image description here

Reading a Rails log with vim, we can see a colored log. But when we use tail -f or less to watch the log, it isn't colorized anymore. Is there any way to see the colored log with tail or less or whatever?

like image 921
Benjamin Avatar asked Jun 24 '12 16:06

Benjamin


People also ask

What does it mean to tail a log?

The tail command, as the name implies, print the last N number of data of the given input. By default it prints the last 10 lines of the specified files. If more than one file name is provided then data from each file is precedes by its file name.

How do you stop tail logs?

In less , you can press Ctrl-C to end forward mode and scroll through the file, then press F to go back to forward mode again. Note that less +F is advocated by many as a better alternative to tail -f .


2 Answers

pass -R to less for it to let colour escape sequences pass through, i.e.

less -R log/development.log

This should result in them being displayed in colour, assuming you are using the proper terminal type

like image 153
Frederick Cheung Avatar answered Sep 30 '22 16:09

Frederick Cheung


tail -f log/development.log | ccze -A

You may need to install ccze

sudo apt-get install ccze

it works better, not ideal but works

like image 36
chech Avatar answered Sep 30 '22 14:09

chech