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:

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:

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:

  '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.

  • kris

    You learn it when you do the project, but I assume you study the language or framework before you do the project, right?

    • Of course. That's the goal. But sometimes you have to dive right in. I have been working with Ruby since I started my first Rails project a few months ago. I just wanted to get better at it, so I chose a project that the result would make my life easier and I dove in.

  • Pingback: Tweets that mention Tailing logs? Give them a touch of color without needing to edit the logs, or the app creating them: --

  • Andy L

    Eric, it would be great to integrate this with Growl, eg: using growl-notify.

    This is my main feature suggestion. 😉

  • stjernstrom

    Nice. I did a similar gem some time ago called capistrano_colors ->

    • Honestly, that was the inspiration for this gem. I have been using your gem for all my cap deployments. I liked the way it worked so much, I imitated it in the configuration. I was going to send you an email thanking you when I found your email address. Looks like you beat me to it. Thanks.

      • stjernstrom

        Coool, Glad that I helped / inspired someone 🙂

  • I get an error when trying to run colortail:

    /Library/Ruby/Gems/1.8/gems/colortail-0.1.4/bin/../lib/colortail/application.rb:28:in `run!': undefined method `push' for Array:Class (NoMethodError)
    from /Library/Ruby/Gems/1.8/gems/colortail-0.1.4/bin/colortail:5
    from /usr/local/bin/colortail:19:in `load'
    from /usr/local/bin/colortail:19

    Do you require ruby 1.9 or something?

    • Nope. I actually introduced a bug in the latest version 0.1.4 that makes colortail eat it when no configuration file is present. If you create a .colortailrc file, this will go away. I will fix this in the next version.

    • This has been fixed in 0.1.5 (as best as I can tell). Please let me know if you continue to experience this issue.

  • One more thing: it seems to make my Terminal font bolder/brighter after running it.

    • I am pretty sure I know why. Can you do me a favor and please submit a ticket (via the Codaset page)? I will try to get it fixed up soon.

  • Brendanity

    This gem made me just a tad happier, and I thought you should know! 😀

    • That's awesome. I'm glad to hear it. Let me know if there is anything else I can add to it to make it even better.

  • Pingback: uberVU - social comments()

Follow My Travels

Buy My Book


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