24 January 2012

Reading colorized/colourized logs.


When you read logs quite frequently, some color/colour on it is good if it helps you to quickly differentiate sections or issues.

There are tools out there for that, but I wanted one that seamlessly replaces the tool that many people use presently to read logs around me, which is the less program on the linux command line.

I did some research and them some more research and finally I found it. It is ccze. However it didn't meet all my previous requirement, seamless integration.

So I created an small script, optimized for the type and size of logs people around me consume. I called it cless (for color less)


  cless
# result: colourize and read as less
# usage: cless <file1> <file2> ...   




Usage examples:
 
# cat vmware-2556-mks-dowcza-* | cless
# cless vmware-2556-mks-dowcza-*
# cless messages
# cless host*
# cless zookeeper.log
# cless inst.log
# cat VSAManager.log* | cless


Code (put on a file called cless and give execution rights):
#===================================
#!/bin/bash

# By Ruben Oct/2011

#cless () {
# result: colourize and read as less
# usage: cless <file1> <file2> ...
cat $@ | ccze -p syslog -A -o nolookups | less -rI ;
# }

#===================================

Too Cool for Internet Explorer