Tailing Logs
am going to be starting a project soon and being the messy programmer I am I will no doubt put in lots of DEBUG messages into my code. Also now that my server is starting to do more things I want to be able to look at various logs and what not to see if everything is running as it should. Just now and again. I’ve set up
monit and monin to keep me informed off most things, but its good to go walking round and seeing what’s happening.
So I want it to be able to view my DEBUG messages /and/ see other log files without any hassle.
Tail is the defacto tool for this job but while it does the job I want to be able see nice pretty lines of colour so that the logs are easily read. The first thing that popped into my head was
ccze – however that site looks dead and the project from what I can gather is also dead. I am sure if I looked hard enough I could find something somewhere that would install it. But that’s too much faffing about. If it can’t be done in 2mins I am not interested.
A quick search in google brought me to
colortail – a ruby gem. Seems to do the trick. The only thing I don’t like is that you can’t (from the little I can see tail back a number of lines – tail -n 20 -f /var/log/xxx.log). I can forgive it that though. The thing I do like is the .colortailrc file you have to write. It will end up being quite powerful I think – a hash of regular expressions linked to a colour and several attributes.
Below is the command to install (thought I might as well give it – might help someone via googling for something) as well as my very first .colourtailrc file. My apache grouping is a bit dirty but it’ll do the job. I’ll post an update once I have used it a bit more.
gem install colortail
[swm@a ~]# cat .colortailrc
Groupings = {
'default' => [
{ :match => /SWM::/, :color => :red, :attribute => :reverse },
{ :match => /ERROR::/, :color => :red, :attribute => :bright },
{ :match => /CRITICAL::/, :color => :red },
{ :match => /DEBUG::/, :color => :green },
{ :match => /ERROR::/, :color => :green },
{ :match => /DIE::/, :color => :yellow },
],
'apache' => [
{ :match => /" 302/, :color => :yellow },
{ :match => /" 400/, :color => :red, :attribute => :bright },
{ :match => /" 401/, :color => :green, :attribute => :reverse },
{ :match => /" 404/, :color => :pink, :attribute => :reverse },
],
}
As I said the apache grouping is a bit dirty – but it works
You can get an example of working groups on their
wiki.