Posts

SQL Logging in ruby console 20 Dec 2009
Tags: log, console, sql

We can do that by typing the following in the console (remember to reload!)

plain
>> ActiveRecord::Base.logger = Logger.new(STDOUT)

But what if we want to turn this off? Just set the logger to nil. (then reload!) Here are two methods that will help automate this feature. Place them in your .irbrc file

ruby
require 'logger'

def logger_on
  set_logger_to Logger.new(STDOUT)
end

def logger_off
  set_logger_to nil
end

def set_logger_to(logger)
  ActiveRecord::Base.logger = logger
  reload!
end

Then you can just type logger_on to turn on SQL logging, or logger_off to turn it off.

Colors in Ruby Console Using Wirble 20 Dec 2009
Tags: log, console, gem, wirble

If you want to have colors in your console, install the wirble gem (Read the documentation).

For some reason, I can't override the colors when I follow the instructions in the README. In case someone's also experiencing this, you can try merging the colors in the Wirble::Colorize::DEFAULT_COLORS constant. Then call the init and colorize methods.

Here's mine (same as with vim's syntax highlighting for ruby and haml).

ruby
Wirble::Colorize::DEFAULT_COLORS.merge!({
  # delimiter colors
  :comma => :none,
  :refers => :none,

  # container colors (hash and array)
  :open_hash => :purple,
  :close_hash => :purple,
  :open_array => :purple,
  :close_array => :purple,

  # object colors
  :open_object => :light_red,
  :object_class => :white,
  :object_addr_prefix => :blue,
  :object_line_prefix => :blue,
  :close_object => :light_red,

  # symbol colors
  :symbol => :red,
  :symbol_prefix => :red,

  # string colors
  :open_string => :purple,
  :string => :red,
  :close_string => :purple,

  # misc colors
  :number => :red,
  :keyword => :brown,
  :class => :green,
  :range => :none
})