Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Allow query_trace to be turned on or off in database.yml

  • Loading branch information...
commit 509fdd26263759dfc9429a94f1bd6a013f927559 1 parent 9ce6f2e
@jonleighton authored
Showing with 14 additions and 6 deletions.
  1. +4 −1 README
  2. +10 −5 lib/query_trace.rb
View
5 README
@@ -9,7 +9,10 @@ have a problem, they will pinpoint the location of that problem for you.
== Usage
-All you have to do is have the plugin installed - QueryTrace takes care of the rest, including:
+1. Install the plugin
+2. Add "query_trace: true" for your development environment in database.yml (you can obviously set it to false to turn off)
+
+QueryTrace takes care of the rest, including:
* Only displaying when at the DEBUG log level
* Honoring your log colorization settings
View
15 lib/query_trace.rb
@@ -17,11 +17,13 @@ def row_even
def log_info_with_trace(sql, name, runtime)
log_info_without_trace(sql, name, runtime)
- return unless @logger and @logger.debug?
- return if / Columns$/ =~ name
+ if @config[:query_trace]
+ return unless @logger and @logger.debug?
+ return if / Columns$/ =~ name
- trace = clean_trace(caller[2..-1])
- @logger.debug(format_trace(trace))
+ trace = clean_trace(caller[2..-1])
+ @logger.debug(format_trace(trace))
+ end
end
def format_trace(trace)
@@ -41,6 +43,9 @@ def format_trace(trace)
def clean_trace(trace)
return trace unless defined?(RAILS_ROOT)
- trace.select{|t| /#{Regexp.escape(File.expand_path(RAILS_ROOT))}/ =~ t}.reject{|t| VENDOR_RAILS_REGEXP =~ t}.collect{|t| t.gsub(RAILS_ROOT + '/', '')}
+ trace = trace.select {|t| /#{Regexp.escape(File.expand_path(RAILS_ROOT))}/ =~ t}
+ trace.reject! {|t| VENDOR_RAILS_REGEXP =~ t}
+ trace.map! {|t| t.gsub(RAILS_ROOT + '/', '')}
+ trace
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.