Skip to content

Instantly share code, notes, and snippets.

@kaichen
Created October 14, 2009 08:57
Show Gist options
  • Save kaichen/209901 to your computer and use it in GitHub Desktop.
Save kaichen/209901 to your computer and use it in GitHub Desktop.
# config/init.rb
DataObjects::Mysql.logger = DataObjects::Logger.new($stdout, :debug) if Merb.env?(:development)
DataObjects::Logger.class_eval do
def push_opened(string)
message = String.new(" ")
if(match = string.match(/FROM\s+[`'"](\w+)[`'"]\s+[WHERE|INNER]/))
model_name = Extlib::Inflection.classify(match[1])
color_sql = string.gsub(/debug\s?#{delimiter}/, ' ').gsub(/(SELECT.+)$/, "\e[36m\\1\e[0m")
message << "\e[4;32m[SELECT #{model_name}]\e[0m#{color_sql}"
else
message << string.gsub(/debug\s?#{delimiter}/, '[SQL] ')
end
message << "\n" unless message[-1] == ?\n
@buffer << message
flush # Force a flush for now until we figure out where we want to use the buffering.
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment