Monthly Archives: June 2011

Using colortail with Rails logs

I recently switched over from using Mongrel as my default server when developing with Rails to using Unicorn, mostly because I wanted to see what alternatives to Passenger are out there, but also because I liked a lot of what the github guys had to say about it, and at least partially because I was curious why rails 3.1 was changing from commented-out-mongrel to commented-out-unicorn in the default Gemfile. In any case, when using ‘unicorn_rails’ as the server, it doesn’t automatically tail the log with pretty colors (well, pretty if you like cyan) in the same way that webrick and mongrel do. So (this is a long preamble), I found colortail.


Colortail is basically Linux’s tail with the ability to customize colors based on extended GNU regexes. It can be installed either with the colortail gem or using apt-get on Ubuntu/Debian. Simple enough, right? You set up your colors in a config file and read it using the -k parameter:

colortail -k /tools/colortail.rails -f log/development.log
Here’s my starter rails config. I’m sure it will grow quickly!
#define BLACK         "\033[0;30m"
#define RED           "\033[0;31m"
#define GREEN         "\033[0;32m"
#define YELLOW        "\033[0;33m"
#define BLUE          "\033[0;34m"
#define MAGENTA       "\033[0;35m"
#define CYAN          "\033[0;36m"
#define WHITE         "\033[0;37m"
#define BRIGHTBLACK   "\033[1;30m"
#define BRIGHTRED     "\033[1;31m"
#define BRIGHTGREEN   "\033[1;32m"
#define BRIGHTYELLOW  "\033[1;33m"
#define BRIGHTBLUE    "\033[1;34m"
#define BRIGHTMAGENTA "\033[1;35m"
#define BRIGHTCYAN    "\033[1;36m"
#define BRIGHTWHITE   "\033[1;37m"
COLOR green
 ^.*Started (.*) for.*at.*$
COLOR yellow
COLOR brightwhite
^Completed 1[0-9][0-9] .*$
^Completed 2[0-9][0-9] .*$
^.*Parameters: (.*)$
COLOR cyan
^Completed 3[0-9][0-9] .*$
^Completed 4[0-9][0-9] .*$
^Completed 5[0-9][0-9] .*$
Note that I pasted in those colors from a source file at the top just so I remember what my options are, they’re just comments.