ColorTail Gem

By eric

One of the best ways to learn something new is to find a project in that realm and do it. I wanted to learn Ruby on Rails, so I wrote a web site. I wanted to learn Python, so I did a project in it for work. Now I want to get better at Ruby, so I wrote a gem. It’s usually not as simple as just picking a project though. It’s much easier to pick and complete a project if you are filling a need. So that’s what I did, I filled a need.

Coming from an SA background, every time I write a script, I use lots of logging. It doesn’t matter whether that script is in Perl, Python, Ruby, Bash, or anything else I write. But what I do keep pretty consistent is that I specify the log levels on the log line. So I get things that look like this:

1
2
3
2010-04-19 11:36:39,734 DEBUG       Getting all mailings for 2010-05-18
2010-04-19 11:36:39,735 INFO        Handling 1 mailing for 2010-05-18
2010-04-19 11:37:16,547 WARNING     Handling 0 mailings for 2010-05-18

When I tail this, it’s usually not a big deal to see what’s what because there aren’t things flying by. Every so often, things fly by and it would just be easier to know what I am looking at. Install the colortail:

1
2
3
4
5
6
7
8
9
10
11
elubow@beacon ~$ sudo gem install colortail
Successfully installed spruz-0.1.0
Successfully installed file-tail-1.0.5
Successfully installed colortail-0.1.3
3 gems installed
Installing ri documentation for spruz-0.1.0...
Installing ri documentation for file-tail-1.0.5...
Installing ri documentation for colortail-0.1.3...
Installing RDoc documentation for spruz-0.1.0...
Installing RDoc documentation for file-tail-1.0.5...
Installing RDoc documentation for colortail-0.1.3...

Add this setup to .colortailrc:

1
2
3
4
5
6
7
8
9
  'syslog' => [
      { :match => /EMERGENCY/,    :color => :red,     :attribute => :reverse },
      { :match => /FATAL/,        :color => :red,     :attribute => :bright },
      { :match => /CRITICAL/,     :color => :red },
      { :match => /DEBUG/,        :color => :green },
      { :match => /ERROR/,        :color => :green },
      { :match => /INFO/,         :color => :none },
      { :match => /WARN/,         :color => :yellow }
  ]

your syslog style log will look like this:

Example of the output from a color grouping
Colored Log Example

I have tried to keep the code flexible enough for you to mix and match combinations. It’s easy to setup and use. Rather than rewriting everything, just check out the repository here at Codaset. Also check out the example groupings wiki page for more ideas.

Full Disclosure: This is my first gem, so there may be some issues, please submit a ticket here so I can fix it. Or if you’d like additional features, I’d be happy to add them, just let me know.

Hope this is as useful for me as it is for you.

Follow My Travels

Buy My Book

Archives

  • 2017
  • 2014
  • 2013
  • 2012
  • 2011
  • 2010
  • 2009
  • 2008
  • 2007
  • 2006

writing