activerecord-colored_log_subscriber 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.travis.yml +4 -0
- data/Appraisals +16 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +21 -0
- data/README.md +51 -0
- data/Rakefile +13 -0
- data/activerecord-sqlcolor-logging.gemspec +26 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/activerecord-colored_log_subscriber.rb +1 -0
- data/lib/activerecord/colored_log_subscriber.rb +10 -0
- data/lib/activerecord/colored_log_subscriber/log_subscriber.rb +107 -0
- data/lib/activerecord/colored_log_subscriber/version.rb +5 -0
- metadata +162 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3bd187a26223b827c0296a1ccfc0933f071e8b9a
|
4
|
+
data.tar.gz: 74a8ccdbc55591ca04fd7b568292cf21f66ced77
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4e74a438a41601f999be3890c64a4a5049f6c9329bb73e7273798831804f8e396a6d0fbfa8a37daf0256305286222e4c9fbe9044bb863b457ae33ff256e72794
|
7
|
+
data.tar.gz: e137da667dfb04f48cfc52ad4c1f7d3465fe48c9da8f7d806ed50576119a5088d62568acd21c8c4c9d210cc4cd5c4c13c6744022e1393b3a52732b96f42d99cb
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Appraisals
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
|
2
|
+
appraise 'activerecord32' do
|
3
|
+
gem 'activerecord', '~> 3.2.0'
|
4
|
+
end
|
5
|
+
|
6
|
+
appraise 'activerecord40' do
|
7
|
+
gem 'activerecord', '4.0.0'
|
8
|
+
end
|
9
|
+
|
10
|
+
appraise 'activerecord41' do
|
11
|
+
gem 'activerecord', '~> 4.1.0'
|
12
|
+
end
|
13
|
+
|
14
|
+
appraise 'activerecord42' do
|
15
|
+
gem 'activerecord', '~> 4.2.0'
|
16
|
+
end
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Ken Collins
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
|
2
|
+
# Colorized SQL Logging Backport for ActiveRecord
|
3
|
+
|
4
|
+
Thanks to the work of Chris Tonkinson (@cmtonkinson) Rails 5 will have granular SQL logging so you can easily see SELECT, INSERT, UPDATE, DELETE, and transaction statements in your log. This gem is a tested backport of that colorized logging feature.
|
5
|
+
|
6
|
+
https://github.com/rails/rails/pull/20607
|
7
|
+
|
8
|
+

|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem 'activerecord-colored_log_subscriber'
|
16
|
+
```
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
```
|
21
|
+
$ bundle
|
22
|
+
```
|
23
|
+
|
24
|
+
Or install it yourself as:
|
25
|
+
|
26
|
+
```
|
27
|
+
$ gem install activerecord-colored_log_subscriber
|
28
|
+
```
|
29
|
+
|
30
|
+
## Development
|
31
|
+
|
32
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
33
|
+
|
34
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
35
|
+
|
36
|
+
We use the [appraisal](https://github.com/thoughtbot/appraisal) gem to help us generate the individual Gemfiles for each ActiveRecord version and to run the tests locally against each generated Gemfile. The `bundle exec rake appraisal test` command actually runs our test suite against all Rails versions in our `Appraisal` file. If you want to run the tests for a specific Rails version, use `rake -T` for a list. For example, the following command will run the tests for Rails 3.2 only.
|
37
|
+
|
38
|
+
```shell
|
39
|
+
$ bundle exec appraisal activerecord32 rake test
|
40
|
+
```
|
41
|
+
|
42
|
+
|
43
|
+
## Contributing
|
44
|
+
|
45
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/customink/activerecord-colored_log_subscriber.
|
46
|
+
|
47
|
+
|
48
|
+
## License
|
49
|
+
|
50
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
51
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'activerecord/colored_log_subscriber/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "activerecord-colored_log_subscriber"
|
8
|
+
spec.version = ActiveRecord::ColoredLogSubscriber::VERSION
|
9
|
+
spec.authors = ["Ken Collins"]
|
10
|
+
spec.email = ["kcollins@customink.com"]
|
11
|
+
spec.summary = 'Colorized SQL Logging Backport for ActiveRecord'
|
12
|
+
spec.description = 'Colorized SQL Logging Backport for ActiveRecord. See http://git.io/vmlOb'
|
13
|
+
spec.homepage = "https://github.com/customink/activerecord-colored_log_subscriber"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
16
|
+
spec.bindir = "exe"
|
17
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
spec.add_runtime_dependency 'activerecord', '>= 3.2', '< 5.0'
|
20
|
+
spec.add_development_dependency 'appraisal'
|
21
|
+
spec.add_development_dependency 'bundler'
|
22
|
+
spec.add_development_dependency 'rake'
|
23
|
+
spec.add_development_dependency 'minitest'
|
24
|
+
spec.add_development_dependency 'pry'
|
25
|
+
spec.add_development_dependency 'sqlite3'
|
26
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "activerecord-colored_log_subscriber"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'activerecord/colored_log_subscriber'
|
@@ -0,0 +1,107 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module ColoredLogSubscriber
|
3
|
+
module LogSubscriber
|
4
|
+
|
5
|
+
module Base
|
6
|
+
|
7
|
+
def odd?
|
8
|
+
false
|
9
|
+
end
|
10
|
+
|
11
|
+
def sql_color(sql)
|
12
|
+
case sql
|
13
|
+
when /\s*\Ainsert/i then ActiveSupport::LogSubscriber::GREEN
|
14
|
+
when /\s*\Aselect/i then ActiveSupport::LogSubscriber::BLUE
|
15
|
+
when /\s*\Aupdate/i then ActiveSupport::LogSubscriber::YELLOW
|
16
|
+
when /\s*\Adelete/i then ActiveSupport::LogSubscriber::RED
|
17
|
+
when /transaction\s*\Z/i then ActiveSupport::LogSubscriber::CYAN
|
18
|
+
else ActiveSupport::LogSubscriber::MAGENTA
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
module ThreeTwo
|
25
|
+
|
26
|
+
def sql(event)
|
27
|
+
self.class.runtime += event.duration
|
28
|
+
return unless logger.debug?
|
29
|
+
payload = event.payload
|
30
|
+
return if 'SCHEMA' == payload[:name]
|
31
|
+
name = '%s (%.1fms)' % [payload[:name], event.duration]
|
32
|
+
sql = payload[:sql].squeeze(' ')
|
33
|
+
binds = nil
|
34
|
+
unless (payload[:binds] || []).empty?
|
35
|
+
binds = " " + payload[:binds].map { |col,v|
|
36
|
+
if col
|
37
|
+
[col.name, v]
|
38
|
+
else
|
39
|
+
[nil, v]
|
40
|
+
end
|
41
|
+
}.inspect
|
42
|
+
end
|
43
|
+
name = color(name, nil, true)
|
44
|
+
sql = color(sql, sql_color(sql), true)
|
45
|
+
debug " #{name} #{sql}#{binds}"
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
module FourZero
|
51
|
+
|
52
|
+
def sql(event)
|
53
|
+
self.class.runtime += event.duration
|
54
|
+
return unless logger.debug?
|
55
|
+
payload = event.payload
|
56
|
+
return if ActiveRecord::LogSubscriber::IGNORE_PAYLOAD_NAMES.include?(payload[:name])
|
57
|
+
name = "#{payload[:name]} (#{event.duration.round(1)}ms)"
|
58
|
+
sql = payload[:sql].squeeze(' ')
|
59
|
+
binds = nil
|
60
|
+
unless (payload[:binds] || []).empty?
|
61
|
+
binds = " " + payload[:binds].map { |col,v|
|
62
|
+
render_bind(col, v)
|
63
|
+
}.inspect
|
64
|
+
end
|
65
|
+
name = color(name, nil, true)
|
66
|
+
sql = color(sql, sql_color(sql), true)
|
67
|
+
debug " #{name} #{sql}#{binds}"
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
module FourOneAndTwo
|
73
|
+
|
74
|
+
def sql(event)
|
75
|
+
self.class.runtime += event.duration
|
76
|
+
return unless logger.debug?
|
77
|
+
payload = event.payload
|
78
|
+
return if ActiveRecord::LogSubscriber::IGNORE_PAYLOAD_NAMES.include?(payload[:name])
|
79
|
+
name = "#{payload[:name]} (#{event.duration.round(1)}ms)"
|
80
|
+
sql = payload[:sql]
|
81
|
+
binds = nil
|
82
|
+
unless (payload[:binds] || []).empty?
|
83
|
+
binds = " " + payload[:binds].map { |col,v|
|
84
|
+
render_bind(col, v)
|
85
|
+
}.inspect
|
86
|
+
end
|
87
|
+
name = color(name, nil, true)
|
88
|
+
sql = color(sql, sql_color(sql), true)
|
89
|
+
debug " #{name} #{sql}#{binds}"
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
ActiveSupport::Notifications.notifier.listeners_for('sql.active_record').each { |listener|
|
95
|
+
next unless listener.inspect =~ /ActiveRecord::LogSubscriber/
|
96
|
+
delegate = listener.instance_variable_get :@delegate
|
97
|
+
delegate.extend Base
|
98
|
+
case ActiveRecord::VERSION::STRING
|
99
|
+
when /\A3.2/ then delegate.extend ThreeTwo
|
100
|
+
when /\A4.0/ then delegate.extend FourZero
|
101
|
+
when /\A4.[12]/ then delegate.extend FourOneAndTwo
|
102
|
+
end
|
103
|
+
}
|
104
|
+
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
metadata
ADDED
@@ -0,0 +1,162 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: activerecord-colored_log_subscriber
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ken Collins
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.2'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '5.0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.2'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '5.0'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: appraisal
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: bundler
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rake
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: minitest
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: pry
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: sqlite3
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
description: Colorized SQL Logging Backport for ActiveRecord. See http://git.io/vmlOb
|
118
|
+
email:
|
119
|
+
- kcollins@customink.com
|
120
|
+
executables: []
|
121
|
+
extensions: []
|
122
|
+
extra_rdoc_files: []
|
123
|
+
files:
|
124
|
+
- ".gitignore"
|
125
|
+
- ".travis.yml"
|
126
|
+
- Appraisals
|
127
|
+
- Gemfile
|
128
|
+
- LICENSE.txt
|
129
|
+
- README.md
|
130
|
+
- Rakefile
|
131
|
+
- activerecord-sqlcolor-logging.gemspec
|
132
|
+
- bin/console
|
133
|
+
- bin/setup
|
134
|
+
- lib/activerecord-colored_log_subscriber.rb
|
135
|
+
- lib/activerecord/colored_log_subscriber.rb
|
136
|
+
- lib/activerecord/colored_log_subscriber/log_subscriber.rb
|
137
|
+
- lib/activerecord/colored_log_subscriber/version.rb
|
138
|
+
homepage: https://github.com/customink/activerecord-colored_log_subscriber
|
139
|
+
licenses:
|
140
|
+
- MIT
|
141
|
+
metadata: {}
|
142
|
+
post_install_message:
|
143
|
+
rdoc_options: []
|
144
|
+
require_paths:
|
145
|
+
- lib
|
146
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
147
|
+
requirements:
|
148
|
+
- - ">="
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: '0'
|
151
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
152
|
+
requirements:
|
153
|
+
- - ">="
|
154
|
+
- !ruby/object:Gem::Version
|
155
|
+
version: '0'
|
156
|
+
requirements: []
|
157
|
+
rubyforge_project:
|
158
|
+
rubygems_version: 2.4.8
|
159
|
+
signing_key:
|
160
|
+
specification_version: 4
|
161
|
+
summary: Colorized SQL Logging Backport for ActiveRecord
|
162
|
+
test_files: []
|