Colour tail of Apache logs

17,986

Solution 1

I'm using multitail to monitor logs, it includes coloring as well as multiple logfile monitoring either merged or in windows. Give it a try.

Solution 2

Any reason why you can't use something like this:

tail -f FILE | grep --color=always KEYWORD

source: commandlinefu.com

Solution 3

I use a small script with grep combinations to get some colors:

#!/bin/bash
shopt -s expand_aliases

alias grey-grep="GREP_COLOR='1;30' grep -E --color=always --line-buffered"
alias red-grep="GREP_COLOR='1;31' grep -E --color=always --line-buffered"
alias green-grep="GREP_COLOR='1;32' grep -E --color=always --line-buffered"
alias yellow-grep="GREP_COLOR='1;33' grep -E --color=always --line-buffered"
alias cyan-grep="GREP_COLOR='1;36' grep -E --color=always --line-buffered"

tail -1000f /var/log/apache2/error.log | grey-grep ".*PerformanceLogger.*|$" | cyan-grep "INFO|$" | yellow-grep "WARN|$" | red-grep "[ERROR].*|[FATAL].*|$" | green-grep "***|$"

The point is that every chained grep add a different color. So the result is something like: Apache log with some colors

Solution 4

Found this: http://fixunix.com/unix/83044-tail-color.html

tail -f file | perl -pe 's/keyword/\e[1;31;43m$&\e[0m/g'

This only works on ANSI terminals, but all others have become virtually extinct. \e[...m ist the ANSI escape sequence SGR "select graphic rendition". The "..." can be replaced by some semicolon-separated integers, with the meaning:

0 : all attributes off 1 : bold 31 : foreground red 43 : background yellow

"keyword", of course, can be any perl regular expression:

(foo|bar) highlight the strings foo and bar \b((foo|bar)\b highlight the words foo and bar .\b((foo|bar)\b. highlight the whole line that contains the words foo or bar

Or, the easy way, just install colortail Its probably in your favorite repo (dag for CentOS)

http://developwithstyle.com/articles/2010/04/20/tail-your-logs-with-a-touch-of-color.html

http://joakimandersson.se/projects/colortail/

Share:
17,986
Cherian
Author by

Cherian

Co-founder of Cucumbertown. Ex-Zynga, cook, dreamer and lots more… Blog Twitter Facebook LinkedIn Bio Google Reader Shared Items

Updated on September 17, 2022

Comments

  • Cherian
    Cherian almost 2 years

    Monitoring apache logs with tail –f tends gets very frustrating for the eyes after a while. Are there any tool/options to colorize the log outputs? Maybe signal FATAL with red, etc...

  • Grizly
    Grizly almost 14 years
  • Grizly
    Grizly almost 14 years
    Yeah, multitail is best
  • SabreWolfy
    SabreWolfy over 10 years
    Did you test it? IT doesn't output anything for me.
  • Michal Mau
    Michal Mau about 9 years
    This filters the output as well, so any line without KEYWORD will be ignored.
  • Garrett
    Garrett about 9 years
    The OP seems to be implying he's looking for a keyword or words. Unless the file is multiline in nature (which apache logs generally are not), then this answer is sufficient.