active_record_query_trace 1.5.3 → 1.5.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: beb00d74cca25d62e2e10e5c8351992b27e6da2a
4
- data.tar.gz: 1975b9908d1fd5b3ae34eb5b74f5af449a6463b7
3
+ metadata.gz: 45e5fb5ece85b56cde741aab63f6d4ef1cdd4674
4
+ data.tar.gz: 75090841d4650bd2ebde1517fc040fec661a25a1
5
5
  SHA512:
6
- metadata.gz: 43264d2d1f758bcf947509619ef36a38c95800391fca73bd9a6fa55351db310634f26846b3f05c5e9bb80609de892d30c20b817b44eaa7971258dd4f1725653e
7
- data.tar.gz: 225b5000e7be755931e7fe6c545634e75bcfe45a00fca466fbaf8889ed598ad1d7389989e1449a49b05ae1a9d0d84bf07aebd5d23c6e9fa0b7cd55144d8042ca
6
+ metadata.gz: 0a1ff57686ca621ef4cd4ed12dadcb0bd6b4f9b2f425492bf3d814e74ff4e4e362ad24985b17f0ccc4ea6f83c8e5f631834ba3cedb9401204cd6dfbb9b3eb377
7
+ data.tar.gz: 676166a2fa21b3975290260fba1d8bc83db77a25a765a33bd800a5eb9f8266f823b1da0d3c6e8d181ad37ee92e98ccbfe0bb05e73fc8a54175c2a381133b13b2
@@ -8,6 +8,7 @@ module ActiveRecordQueryTrace
8
8
  attr_accessor :level
9
9
  attr_accessor :lines
10
10
  attr_accessor :ignore_cached_queries
11
+ attr_accessor :colorize
11
12
  end
12
13
 
13
14
  module ActiveRecord
@@ -19,6 +20,7 @@ module ActiveRecordQueryTrace
19
20
  ActiveRecordQueryTrace.level = :app
20
21
  ActiveRecordQueryTrace.lines = 5
21
22
  ActiveRecordQueryTrace.ignore_cached_queries = false
23
+ ActiveRecordQueryTrace.colorize = false
22
24
 
23
25
  if ActiveRecordQueryTrace.level != :app
24
26
  # Rails by default silences all backtraces that match Rails::BacktraceCleaner::APP_DIRS_PATTERN
@@ -41,10 +43,31 @@ module ActiveRecordQueryTrace
41
43
  return if ActiveRecordQueryTrace.ignore_cached_queries && payload[:name] == 'CACHE'
42
44
 
43
45
  cleaned_trace = clean_trace(caller)[index].join("\n from ")
44
- debug(" Query Trace > " + cleaned_trace) unless cleaned_trace.blank?
46
+ debug(" Query Trace > " + colorize_text(cleaned_trace)) unless cleaned_trace.blank?
45
47
  end
46
48
  end
47
49
 
50
+ # Allow query to be colorized in the terminal
51
+ def colorize_text(text)
52
+ return text unless ActiveRecordQueryTrace.colorize
53
+ # Try to convert the choosen color from string to integer or try
54
+ # to use the colorize as the color code
55
+ colors = {
56
+ true => "38", "blue" => "34", "light red" => "1;31",
57
+ "black" => "30", "purple" => "35", "light green" => "1;32",
58
+ "red" => "31", "cyan" => "36", "yellow" => "1;33",
59
+ "green" => "32", "gray" => "37", "light blue" => "1;34",
60
+ "brown" => "33", "dark gray" => "1;30", "light purple" => "1;35",
61
+ "white" => "1;37", "light cyan" => "1;36"
62
+ }
63
+ color_code = colors[ActiveRecordQueryTrace.colorize] ||
64
+ ActiveRecordQueryTrace.colorize.to_s
65
+ unless /\d+(;\d+){0,1}/.match(color_code)
66
+ raise "Invalid color. Use one of #{ colors.keys } or a valid color code"
67
+ end
68
+ "\e[#{ color_code }m#{ text }\e[0m"
69
+ end
70
+
48
71
  def clean_trace(trace)
49
72
  # Rails relies on backtrace cleaner to set the application root directory filter
50
73
  # the problem is that the backtrace cleaner is initialized before the application
@@ -1,3 +1,3 @@
1
1
  module ActiveRecordQueryTrace
2
- VERSION = '1.5.3'
2
+ VERSION = '1.5.4'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record_query_trace
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.3
4
+ version: 1.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cody Caughlan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-16 00:00:00.000000000 Z
11
+ date: 2016-10-12 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Print stack trace of all queries to the Rails log. Helpful to find where
14
14
  queries are being executed in your application.
@@ -17,12 +17,8 @@ executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
- - active_record_query_trace.gemspec
21
- - HISTORY.md
22
20
  - lib/active_record_query_trace.rb
23
21
  - lib/version.rb
24
- - MIT-LICENSE
25
- - README.md
26
22
  homepage: https://github.com/ruckus/active-record-query-trace
27
23
  licenses:
28
24
  - MIT
@@ -49,4 +45,3 @@ specification_version: 4
49
45
  summary: Print stack trace of all queries to the Rails log. Helpful to find where
50
46
  queries are being executed in your application.
51
47
  test_files: []
52
- has_rdoc:
data/HISTORY.md DELETED
@@ -1,31 +0,0 @@
1
- ## 1.5.2 (2015-11-12)
2
-
3
- * Track queries from 'lib' or 'engines' folders. Thanks to @amalkov
4
-
5
- * Updates to log formatting to make it look better. Thanks to @carsonreinke
6
-
7
- ## 1.5 (2015-09-23)
8
-
9
- Merge pull request #13 from mtyeh411/fix_root_trace_filter
10
-
11
- Fixed Rails 4.2 backtrace_cleaner root filter with sql-logging gem
12
-
13
- Thank you @mtyeh411
14
-
15
- ## 1.4 (2015-03-05)
16
-
17
- Support for ignoring `ActiveRecord` cached queries that show up in the log with a `CACHE` prefix.
18
-
19
- ```ruby
20
- ActiveRecordQueryTrace.ignore_cached_queries = true
21
- ```
22
-
23
- See this Pull-Request for additional notes on how these cached queries can also be skipped from the log file:
24
-
25
- https://github.com/ruckus/active-record-query-trace/pull/10
26
-
27
- Thank you to @tinynumbers for this contribution.
28
-
29
- ## < 1.3
30
-
31
- Unavailable. Sorry, I was not keep tracking of history prior to `1.4`
@@ -1,9 +0,0 @@
1
- The MIT License
2
-
3
- Copyright (c) 2011
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
-
7
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
-
9
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md DELETED
@@ -1,81 +0,0 @@
1
- Logs the source of execution of all queries to the Rails log. Helpful to track down where queries are being executed in your application, for performance optimizations most likely.
2
-
3
- ## Install
4
-
5
- Install the latest stable release:
6
-
7
- `gem install active_record_query_trace`
8
-
9
- In Rails, add it to your Gemfile, then restart the server:
10
-
11
- ```ruby
12
- gem 'active_record_query_trace'
13
- ```
14
-
15
- ##Usage
16
-
17
- Enable it in an initializer:
18
-
19
- ```ruby
20
- ActiveRecordQueryTrace.enabled = true
21
- ```
22
-
23
- ## Options
24
-
25
- There are three levels of debug.
26
-
27
- 1. app - includes only files in your app/ directory.
28
- 2. full - includes files in your app as well as rails.
29
- 3. rails - alternate output of full backtrace, useful for debugging gems.
30
-
31
- ```ruby
32
- ActiveRecordQueryTrace.level = :app # default
33
- ```
34
-
35
- By default, a backtrace will be logged for every query, even cached queries that do not actually hit the database. You might find it useful not to print the backtrace for cached queries:
36
-
37
- ```ruby
38
- ActiveRecordQueryTrace.ignore_cached_queries = true # Default is false.
39
- ```
40
-
41
- Additionally, if you are working with a large app, you may wish to limit the number of lines displayed for each query.
42
-
43
- ```ruby
44
- ActiveRecordQueryTrace.lines = 10 # Default is 5. Setting to 0 includes entire trace.
45
- ```
46
-
47
- ## Output
48
-
49
- When enabled every query source will be logged like:
50
-
51
- ```
52
- IntuitAccount Load (1.2ms) SELECT "intuit_accounts".* FROM "intuit_accounts" WHERE "intuit_accounts"."user_id" = 20 LIMIT 1
53
- Called from:
54
- app/views/users/edit.html.haml:78:in `block in _app_views_users_edit_html_haml___1953197429694975654_70177901460360'
55
- app/views/users/edit.html.haml:16:in `_app_views_users_edit_html_haml___1953197429694975654_70177901460360'
56
- ```
57
-
58
- Requirements
59
- ------------
60
- Rails 3+
61
-
62
- Copyright (c) 2011 Cody Caughlan
63
-
64
- Permission is hereby granted, free of charge, to any person obtaining
65
- a copy of this software and associated documentation files (the
66
- "Software"), to deal in the Software without restriction, including
67
- without limitation the rights to use, copy, modify, merge, publish,
68
- distribute, sublicense, and/or sell copies of the Software, and to
69
- permit persons to whom the Software is furnished to do so, subject to
70
- the following conditions:
71
-
72
- The above copyright notice and this permission notice shall be
73
- included in all copies or substantial portions of the Software.
74
-
75
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
76
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
77
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
78
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
79
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
80
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
81
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,14 +0,0 @@
1
- $:.unshift File.expand_path("../lib", __FILE__)
2
- require 'version'
3
-
4
- Gem::Specification.new do |gem|
5
- gem.name = 'active_record_query_trace'
6
- gem.version = ActiveRecordQueryTrace::VERSION
7
- gem.summary = "Print stack trace of all queries to the Rails log. Helpful to find where queries are being executed in your application."
8
- gem.description = gem.summary
9
- gem.authors = ["Cody Caughlan"]
10
- gem.email = 'toolbag@gmail.com'
11
- gem.homepage = 'https://github.com/ruckus/active-record-query-trace'
12
- gem.files = Dir["**/*"]
13
- gem.license = 'MIT'
14
- end