clog - add colours to your log life (and files)

Developers often have to look at log files. This is sometimes boring, sometimes tedious, but it's a fact of life. It would really help if some special lines, such as errors, warnings etc. could stand out. One way to do it is to use the clog utility.

To make clog usage more streamlined from a terminal, you can define this bash function:

  1. # pipe a log file through clog to get colours
  2. function logless
  3. {
  4.     if [ -z "$1" ]; then
  5.         echo "No file given, exiting" 1>&2
  6.     else
  7.         cat $1 | clog | less -R
  8.     fi
  9. }

Don't forget, you need to configure clog so that it is able to recognize the format of your log files, since there is no way it can know it in advance. If you happen to be using glog (Google log) library in its default configuration, try adding these settings to your .clogrc file:

  1. default rule /^W/   --> yellow line
  2. default rule /^E/   --> red line

Read clog manual for further information. Happy logging!

Add new comment