How to: turn off ANSI codes in Rails console

Small tip: when you happen to be running Rails in a console that doesn’t understand ANSI codes (those pesky ←[4;36;1m and ←[0;1m that clutter your display), like for example Windows’ cmd, you can turn them off with:

if RUBY_PLATFORM =~ /mswin32/
  ActiveRecord::Base.colorize_logging = false
end

Put this in config/environments/development.rb and restart script/server.

Took me a while to find it, so I thought I’d post it for posterity :)


3 responses to “How to: turn off ANSI codes in Rails console

  • acemtp

    useful thanks

  • andrewclarkeau

    And for anyone hunting for a solution in rails 3.1, try this

    # disappear the annoying ANSI codes for PowerShell and cmd
    if RUBY_PLATFORM =~ /mswin|mingw/i
    ActiveSupport::LogSubscriber.colorize_logging = false
    end

  • andrewclarkeau

    errrm, I mean, Rails 3.2 – i’m on 3.2.1 so my brain wrote 3.1. duhhh.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: