Created
October 14, 2009 08:57
-
-
Save kaichen/209901 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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