15 Answers
15

Try out multitail. This is an übergeneralization of tail -f. You can watch multiple files in separate windows, highlight lines based on their content, and more.

multitail -c /path/to/log

The colors are configurable. If the default color scheme doesn't work for you, write your own in the config file. For example, call multitail -cS amir_log /path/to/log with the following ~/.multitailrc:

colorscheme:amir_log
cs_re:green:INFO
cs_re:red:SEVERE

Another solution, if you're on a server where it's inconvenient to install non-standard tools, is to combine tail -f with sed or awk to add color selection control sequences. This requires tail -f to flush its standard output without delay even when its standard output is a pipe, I don't know if all implementations do this.

how can you do this with sed? (sorry for being lazy and not figuring it out myself!) But would you please add a sed example as well.
–
AliNov 28 '11 at 16:41

4

@Ali Sed is less convenient because it doesn't have a syntax for the escape character, you need to have it literally in the script or use a shell quoting method to work it in. I recommend that you use awk.
–
GillesNov 28 '11 at 17:18

@Gilles Thank you for sharing your knowledge. Though, is there a way to do this with vim as like Emacs does?
–
BenjaminJun 24 '12 at 17:01

2

@Gilles In your tail -f with awk code, if a string doesn't have INFO and SEVERE, the string isn't be printed. How can I print the remain strings either? (The string doesn't need to be colored)
–
BenjaminJun 29 '12 at 10:32

2

@Benjamin Add ; next before the closing braces to skip further processing, and a new processing line 1 {print} at the end (1 means always).
–
GillesJun 29 '12 at 11:58

This is exactly what I needed: lightweight and simple. The coloring isn't exactly right for my log types (custom logs) but any coloring makes it easier for me to follow a log.
–
rennatOct 21 '11 at 19:49

For me 'grc' on Debian errors out with: OSError: [Errno 13] Permission denied. Also it depends on Python being installed so it's not relaly lightweight unless you already have it. I have found 'ccze' to work much better, ex. 'tail -f -n 50 /var/log/starbound-server.log | ccze -A'.
–
Daniel SokolowskiDec 9 '13 at 3:56

grc default settings in Ubuntu didn't display nice for syslogs or mail.log. It is not easy to understand how to customize it.
–
lepeJan 27 '14 at 3:34

I found it quicker and easier way to colorize than multitail. Just did a quick install via source on my CentOS system and upgraded my life. Will install on my other systems too.
–
zeeshanJul 12 '14 at 9:51

You can also make your terminal send an alert or "beep" by adding \007 to the end of the regex, like so: perl -pe 's/(ERROR)/\033[31m$1\033[0m\007/g;'. This works awesome if you are using tmux with set -g bell-action any, in which case if you have your log tailing in another window, that window name will alert whenever the regex finds a match.
–
jonyamoNov 13 '12 at 4:15

@AmirAfghani This is a linux/unix SE site, therefore I am not sure why you thought it would work on mac.
–
BЈовићJun 4 '13 at 6:06

+1 available at Ubuntu repositories. What I like of colortail compared to ccze is that you can customize freely your patterns using RegEx. Available colors: black, brightblack, white, brightwhite, magenta, brightmagenta, cyan, brightcyan, green,‌​brightgreen, yellow, brightyellow, red,brightred, blue, brightblue. Unfortunately there is no way to set bold or other colors like orange.
–
lepeJan 27 '14 at 3:55

I would like to correct one point about my previous comment: "bright"+color includes "bold" (some colors will actually look brighter as well)
–
lepeJan 27 '14 at 4:25

It looks nice. Its a big package compared to others in this list (26MB). It supports a huge list of languages. It can be customized modifying the config files located at: /usr/share/source-highlight/*.lang (Ubuntu). If you need something simple, go with ccze or colortail.
–
lepeJan 27 '14 at 3:46

looks like it depends on boost, which is around 462MB
–
ecsosMay 29 '14 at 21:34

If you want color text with awk the story is a little bit complex but more powerfull, for example:

[root@linubox mydir]# tail -f /var/log/messages | awk '{if ($5 ~ /INFO/) print "\033[1;32m"$0"\033[0m"; else if ($1 ~ /SEVERE/) print "\033[1;31m"$0"\033[0m"; else print $0}'
this entry is an INFOSEVERE this entry is a warn!
this is another ENTRY
this entry is an INFO
this is another ENTRY
this entry is an INFOSEVERE this entry is a warn!

with each line in its own color.

There are many other way to get colorized text from shell with other tools and they are well descripted by other members.