less color is more color

February 10, 2007 Alex Chaffee

Ever do “less log/development.log” and see the following?

ESC[4;35;1mSQL (0.001084)ESC[0m ESC[0mSET character_set_results = utf8;ESC[0m
ESC[4;36;1mSQL (0.001792)ESC[0m ESC[0;1mSHOW TABLESESC[0m

Wouldn’t it be nicer to see the colorization like when you’re tailing the log with tail -f? Try using -R:

less -R log/development.log

Then you’ll see

SQL (0.001084) SET character_set_results = utf8;
SQL (0.001792) SHOW TABLES

A bit more legible, eh wot old chaps?

Works on Mac and Cygwin too.

And -X makes it not clear the screen when you stop less, so you get to keep seeing what you were just seeing.

So that means you may want to put

alias less="less -RX"


export LESS="-RX"

in your .bash_profile.

Also, if you don’t want the fancy colors at all, specify

ActiveRecord::Base.colorize_logging = false

in your environment file (e.g. test.rb.) We’re doing that in our test.rb so we can more clearly read the output from our CruiseControl build.

About the Author


Do not fear the code — The code should fear YOU!
Do not fear the code — The code should fear YOU!

Never be afraid to refactor. It may seem scary right now, but it will only become more daunting as the cod...

My pair the be-whiskered
My pair the be-whiskered

SpringOne 2021

Register Now