lograge-sql 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +20 -0
- data/.travis.yml +11 -2
- data/Gemfile +2 -0
- data/Rakefile +3 -1
- data/bin/console +1 -0
- data/gemfiles/lograge10.gemfile +7 -0
- data/gemfiles/lograge11.gemfile +7 -0
- data/lib/lograge/sql.rb +6 -7
- data/lib/lograge/sql/extension.rb +14 -1
- data/lib/lograge/sql/railtie.rb +4 -1
- data/lib/lograge/sql/version.rb +4 -1
- data/lograge-sql.gemspec +8 -5
- metadata +48 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: edb09eb5b84cec3d09b2c25e4a33c6e8dd22d7d836f6532e5b4554e1ae31dfab
|
4
|
+
data.tar.gz: 646b5d6635260962c7685532e2d574c74df016914a800491688e1be063fa0bba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e99f15caca6f929045901ab7abf57431953e6d157d2423fa52ff781aa5abeb2f21224bce0304b6b127d8d5a50f2d368ad82780673a7b0db5223cbb56f3de1f6
|
7
|
+
data.tar.gz: 8425ab339321fbcf3fad76c607ef2097d05a05527837e21daf6e307e67157bdef5eb573e42892d2cbbf53b83cf66729552b473540e29342a6fe6c1d4d95e857b
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-performance
|
3
|
+
|
4
|
+
AllCops:
|
5
|
+
DisplayCopNames: true
|
6
|
+
DisplayStyleGuide: true
|
7
|
+
TargetRubyVersion: 2.3
|
8
|
+
|
9
|
+
Metrics/BlockLength:
|
10
|
+
Exclude:
|
11
|
+
- spec/**/*.rb
|
12
|
+
|
13
|
+
Metrics/LineLength:
|
14
|
+
Max: 120
|
15
|
+
Exclude:
|
16
|
+
- spec/**/*.rb
|
17
|
+
|
18
|
+
Style/Documentation:
|
19
|
+
Exclude:
|
20
|
+
- 'spec/**/*'
|
data/.travis.yml
CHANGED
@@ -1,7 +1,16 @@
|
|
1
1
|
language: ruby
|
2
|
+
cache: bundler
|
2
3
|
rvm:
|
4
|
+
- 2.3
|
5
|
+
- 2.4
|
3
6
|
- 2.5
|
4
|
-
|
7
|
+
- 2.6
|
8
|
+
before_install:
|
9
|
+
- gem uninstall -v '>= 2' -i $(rvm gemdir)@global -ax bundler || true
|
10
|
+
- gem install bundler -v '~> 1.17'
|
11
|
+
gemfile:
|
12
|
+
- gemfiles/lograge10.gemfile
|
13
|
+
- gemfiles/lograge11.gemfile
|
5
14
|
deploy:
|
6
15
|
provider: rubygems
|
7
16
|
api_key:
|
@@ -10,5 +19,5 @@ deploy:
|
|
10
19
|
on:
|
11
20
|
tags: true
|
12
21
|
repo: iMacTia/lograge-sql
|
13
|
-
rvm: 2.
|
22
|
+
rvm: 2.6
|
14
23
|
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
data/bin/console
CHANGED
data/lib/lograge/sql.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'lograge/sql/version'
|
2
4
|
|
3
5
|
module Lograge
|
6
|
+
# Main gem module
|
4
7
|
module Sql
|
5
|
-
|
6
8
|
class << self
|
7
|
-
|
8
9
|
# Format SQL log
|
9
10
|
attr_accessor :formatter
|
10
11
|
# Extract information from SQL event
|
@@ -20,21 +21,19 @@ module Lograge
|
|
20
21
|
|
21
22
|
# By default, the output is a concatenated string of all extracted events
|
22
23
|
def default_formatter
|
23
|
-
|
24
|
+
proc do |sql_queries|
|
24
25
|
%('#{sql_queries.join("\n")}')
|
25
26
|
end
|
26
27
|
end
|
27
28
|
|
28
|
-
# By default, only extract values required for the default_formatter and
|
29
|
+
# By default, only extract values required for the default_formatter and
|
29
30
|
# already convert to a string
|
30
31
|
def default_extract_event
|
31
|
-
|
32
|
+
proc do |event|
|
32
33
|
"#{event.payload[:name]} (#{event.duration.to_f.round(2)}) #{event.payload[:sql]}"
|
33
34
|
end
|
34
35
|
end
|
35
|
-
|
36
36
|
end
|
37
|
-
|
38
37
|
end
|
39
38
|
end
|
40
39
|
|
@@ -1,10 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Lograge
|
2
4
|
module Sql
|
5
|
+
# Module used to extend Lograge
|
3
6
|
module Extension
|
7
|
+
# Overrides `Lograge::RequestLogSubscriber#extract_request` do add SQL queries
|
4
8
|
def extract_request(event, payload)
|
5
9
|
super.merge!(extract_sql_queries)
|
6
10
|
end
|
7
11
|
|
12
|
+
# Collects all SQL queries stored in the Thread during request processing
|
8
13
|
def extract_sql_queries
|
9
14
|
sql_queries = Thread.current[:lograge_sql_queries]
|
10
15
|
return {} unless sql_queries
|
@@ -20,17 +25,25 @@ module Lograge
|
|
20
25
|
end
|
21
26
|
|
22
27
|
module Lograge
|
28
|
+
# Log subscriber to replace ActiveRecord's default one
|
23
29
|
class ActiveRecordLogSubscriber < ActiveSupport::LogSubscriber
|
30
|
+
# Every time there's an SQL query, stores it into the Thread.
|
31
|
+
# They'll later be access from the RequestLogSubscriber.
|
24
32
|
def sql(event)
|
25
33
|
ActiveRecord::LogSubscriber.runtime += event.duration
|
26
34
|
return if event.payload[:name] == 'SCHEMA'
|
35
|
+
|
27
36
|
Thread.current[:lograge_sql_queries] ||= []
|
28
37
|
Thread.current[:lograge_sql_queries] << Lograge::Sql.extract_event.call(event)
|
29
38
|
end
|
30
39
|
end
|
31
40
|
end
|
32
41
|
|
33
|
-
Lograge::RequestLogSubscriber
|
42
|
+
if defined?(Lograge::RequestLogSubscriber)
|
43
|
+
Lograge::RequestLogSubscriber.prepend Lograge::Sql::Extension
|
44
|
+
else
|
45
|
+
Lograge::LogSubscribers::ActionController.prepend Lograge::Sql::Extension
|
46
|
+
end
|
34
47
|
|
35
48
|
ActiveSupport::LogSubscriber.log_subscribers.each do |subscriber|
|
36
49
|
Lograge.unsubscribe(:active_record, subscriber) if subscriber.is_a?(ActiveRecord::LogSubscriber)
|
data/lib/lograge/sql/railtie.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rails/railtie'
|
2
4
|
require 'active_support/ordered_options'
|
3
5
|
|
4
6
|
module Lograge
|
5
7
|
module Sql
|
8
|
+
# Railtie to automatically setup in Rails
|
6
9
|
class Railtie < Rails::Railtie
|
7
10
|
# To ensure that configuration is not nil when initialise Lograge::Sql.setup
|
8
11
|
config.lograge_sql = ActiveSupport::OrderedOptions.new
|
@@ -12,4 +15,4 @@ module Lograge
|
|
12
15
|
end
|
13
16
|
end
|
14
17
|
end
|
15
|
-
end
|
18
|
+
end
|
data/lib/lograge/sql/version.rb
CHANGED
data/lograge-sql.gemspec
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
5
|
require 'lograge/sql/version'
|
5
6
|
|
@@ -9,8 +10,8 @@ Gem::Specification.new do |spec|
|
|
9
10
|
spec.authors = ['Mattia Giuffrida']
|
10
11
|
spec.email = ['giuffrida.mattia@gmail.com']
|
11
12
|
|
12
|
-
spec.summary =
|
13
|
-
spec.description =
|
13
|
+
spec.summary = 'An extension for Lograge to log SQL queries'
|
14
|
+
spec.description = 'An extension for Lograge to log SQL queries'
|
14
15
|
spec.homepage = 'https://github.com/iMacTia/lograge-sql'
|
15
16
|
spec.license = 'MIT'
|
16
17
|
|
@@ -19,10 +20,12 @@ Gem::Specification.new do |spec|
|
|
19
20
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
21
|
spec.require_paths = ['lib']
|
21
22
|
|
22
|
-
spec.add_runtime_dependency 'lograge', '~> 0.4'
|
23
23
|
spec.add_runtime_dependency 'activerecord', '>= 4', '< 6.0'
|
24
|
+
spec.add_runtime_dependency 'lograge', '~> 0.4'
|
24
25
|
|
25
26
|
spec.add_development_dependency 'bundler', '~> 1.0'
|
26
27
|
spec.add_development_dependency 'rake', '~> 10.0'
|
27
28
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
29
|
+
spec.add_development_dependency 'rubocop'
|
30
|
+
spec.add_development_dependency 'rubocop-performance'
|
28
31
|
end
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lograge-sql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mattia Giuffrida
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-05-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: lograge
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0.4'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0.4'
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: activerecord
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -44,6 +30,20 @@ dependencies:
|
|
44
30
|
- - "<"
|
45
31
|
- !ruby/object:Gem::Version
|
46
32
|
version: '6.0'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: lograge
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0.4'
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0.4'
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: bundler
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -86,6 +86,34 @@ dependencies:
|
|
86
86
|
- - "~>"
|
87
87
|
- !ruby/object:Gem::Version
|
88
88
|
version: '3.0'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: rubocop
|
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: rubocop-performance
|
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'
|
89
117
|
description: An extension for Lograge to log SQL queries
|
90
118
|
email:
|
91
119
|
- giuffrida.mattia@gmail.com
|
@@ -95,12 +123,15 @@ extra_rdoc_files: []
|
|
95
123
|
files:
|
96
124
|
- ".gitignore"
|
97
125
|
- ".rspec"
|
126
|
+
- ".rubocop.yml"
|
98
127
|
- ".travis.yml"
|
99
128
|
- Gemfile
|
100
129
|
- README.md
|
101
130
|
- Rakefile
|
102
131
|
- bin/console
|
103
132
|
- bin/setup
|
133
|
+
- gemfiles/lograge10.gemfile
|
134
|
+
- gemfiles/lograge11.gemfile
|
104
135
|
- lib/lograge/sql.rb
|
105
136
|
- lib/lograge/sql/extension.rb
|
106
137
|
- lib/lograge/sql/railtie.rb
|
@@ -125,8 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
125
156
|
- !ruby/object:Gem::Version
|
126
157
|
version: '0'
|
127
158
|
requirements: []
|
128
|
-
|
129
|
-
rubygems_version: 2.7.8
|
159
|
+
rubygems_version: 3.0.3
|
130
160
|
signing_key:
|
131
161
|
specification_version: 4
|
132
162
|
summary: An extension for Lograge to log SQL queries
|