lograge-sql 1.1.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -0
- data/lib/lograge/active_record_log_subscriber.rb +16 -0
- data/lib/lograge/sql/extension.rb +2 -21
- data/lib/lograge/sql/railtie.rb +2 -2
- data/lib/lograge/sql/version.rb +1 -1
- data/lib/lograge/sql.rb +14 -0
- metadata +14 -80
- data/.gitignore +0 -11
- data/.rspec +0 -2
- data/.rubocop.yml +0 -22
- data/.travis.yml +0 -33
- data/Gemfile +0 -6
- data/bin/console +0 -15
- data/bin/setup +0 -8
- data/gemfiles/lograge10.gemfile +0 -7
- data/gemfiles/lograge11.gemfile +0 -7
- data/lograge-sql.gemspec +0 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '066994b5ce1417ea75cdcb9328eb91c0deb1a2e4530119a2a698356aaccedb28'
|
4
|
+
data.tar.gz: 151e948e7fbd209d7048b4c8fe92afa83d1f9012974abc7d2daf24c29caa2da7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ade265153ed67c440a4135daf39ffe9479adeb5c89b3780f0f91fabf28f96199be19aa646fe1170c0a67a9505fdfcf4172df2d085d0b8f178fb4994888217f2
|
7
|
+
data.tar.gz: 1372c45b1944a73f5a209e9d6581856bb16819a90c3ffc6ab5e0e75158e0e48783ec236dd11aa6883af5c0d7731913a5fe3e1dfddf5e665312fe73821a32e804
|
data/README.md
CHANGED
@@ -23,6 +23,12 @@ In order to enable SQL logging in your application, you'll simply need to add th
|
|
23
23
|
require 'lograge/sql/extension'
|
24
24
|
```
|
25
25
|
|
26
|
+
By default, Lograge::Sql disables default logging on ActiveRecord. To preserve default logging, add this to your lograge initializer:
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
config.lograge_sql.keep_default_active_record_log = true
|
30
|
+
```
|
31
|
+
|
26
32
|
## Customization
|
27
33
|
|
28
34
|
By default, the format is a string concatenation of the query name, the query duration and the query itself joined by `\n` newline:
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Lograge
|
4
|
+
# Log subscriber to replace ActiveRecord's default one
|
5
|
+
class ActiveRecordLogSubscriber < ActiveSupport::LogSubscriber
|
6
|
+
# Every time there's an SQL query, stores it into the Thread.
|
7
|
+
# They'll later be access from the RequestLogSubscriber.
|
8
|
+
def sql(event)
|
9
|
+
ActiveRecord::LogSubscriber.runtime += event.duration
|
10
|
+
return if event.payload[:name] == 'SCHEMA'
|
11
|
+
|
12
|
+
Lograge::Sql.store[:lograge_sql_queries] ||= []
|
13
|
+
Lograge::Sql.store[:lograge_sql_queries] << Lograge::Sql.extract_event.call(event)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'lograge/active_record_log_subscriber'
|
4
|
+
|
3
5
|
module Lograge
|
4
6
|
module Sql
|
5
7
|
# Module used to extend Lograge
|
@@ -24,29 +26,8 @@ module Lograge
|
|
24
26
|
end
|
25
27
|
end
|
26
28
|
|
27
|
-
module Lograge
|
28
|
-
# Log subscriber to replace ActiveRecord's default one
|
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.
|
32
|
-
def sql(event)
|
33
|
-
ActiveRecord::LogSubscriber.runtime += event.duration
|
34
|
-
return if event.payload[:name] == 'SCHEMA'
|
35
|
-
|
36
|
-
Lograge::Sql.store[:lograge_sql_queries] ||= []
|
37
|
-
Lograge::Sql.store[:lograge_sql_queries] << Lograge::Sql.extract_event.call(event)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
29
|
if defined?(Lograge::RequestLogSubscriber)
|
43
30
|
Lograge::RequestLogSubscriber.prepend Lograge::Sql::Extension
|
44
31
|
else
|
45
32
|
Lograge::LogSubscribers::ActionController.prepend Lograge::Sql::Extension
|
46
33
|
end
|
47
|
-
|
48
|
-
ActiveSupport::LogSubscriber.log_subscribers.each do |subscriber|
|
49
|
-
Lograge.unsubscribe(:active_record, subscriber) if subscriber.is_a?(ActiveRecord::LogSubscriber)
|
50
|
-
end
|
51
|
-
|
52
|
-
Lograge::ActiveRecordLogSubscriber.attach_to :active_record
|
data/lib/lograge/sql/railtie.rb
CHANGED
@@ -10,8 +10,8 @@ module Lograge
|
|
10
10
|
# To ensure that configuration is not nil when initialise Lograge::Sql.setup
|
11
11
|
config.lograge_sql = ActiveSupport::OrderedOptions.new
|
12
12
|
|
13
|
-
config.
|
14
|
-
Lograge::Sql.setup(
|
13
|
+
config.to_prepare do
|
14
|
+
Lograge::Sql.setup(Rails.application.config.lograge_sql)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
data/lib/lograge/sql/version.rb
CHANGED
data/lib/lograge/sql.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'lograge/sql/version'
|
4
4
|
|
5
|
+
# Main Lograge module
|
5
6
|
module Lograge
|
6
7
|
# Main gem module
|
7
8
|
module Sql
|
@@ -15,8 +16,21 @@ module Lograge
|
|
15
16
|
def setup(config)
|
16
17
|
Lograge::Sql.formatter = config.formatter || default_formatter
|
17
18
|
Lograge::Sql.extract_event = config.extract_event || default_extract_event
|
19
|
+
|
20
|
+
# Disable existing ActiveRecord logging
|
21
|
+
unless config.keep_default_active_record_log
|
22
|
+
ActiveSupport::LogSubscriber.log_subscribers.each do |subscriber|
|
23
|
+
Lograge.unsubscribe(:active_record, subscriber) if subscriber.is_a?(ActiveRecord::LogSubscriber)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
return unless defined?(Lograge::ActiveRecordLogSubscriber)
|
28
|
+
|
29
|
+
Lograge::ActiveRecordLogSubscriber.attach_to(:active_record)
|
18
30
|
end
|
19
31
|
|
32
|
+
# Gets the store, preferring RequestStore if the gem is found.
|
33
|
+
# @return [Hash, Thread] the RequestStore or the current Thread.
|
20
34
|
def store
|
21
35
|
defined?(RequestStore) ? RequestStore.store : Thread.current
|
22
36
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lograge-sql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mattia Giuffrida
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-01-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -16,104 +16,48 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '5'
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '7.
|
22
|
+
version: '7.1'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: '
|
29
|
+
version: '5'
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '7.
|
32
|
+
version: '7.1'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: lograge
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
36
36
|
requirements:
|
37
37
|
- - "~>"
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version: '0.
|
39
|
+
version: '0.11'
|
40
40
|
type: :runtime
|
41
41
|
prerelease: false
|
42
42
|
version_requirements: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
44
|
- - "~>"
|
45
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: '2.0'
|
54
|
-
type: :development
|
55
|
-
prerelease: false
|
56
|
-
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
requirements:
|
58
|
-
- - "~>"
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
version: '2.0'
|
46
|
+
version: '0.11'
|
61
47
|
- !ruby/object:Gem::Dependency
|
62
48
|
name: rake
|
63
49
|
requirement: !ruby/object:Gem::Requirement
|
64
|
-
requirements:
|
65
|
-
- - "~>"
|
66
|
-
- !ruby/object:Gem::Version
|
67
|
-
version: '10.0'
|
68
|
-
type: :development
|
69
|
-
prerelease: false
|
70
|
-
version_requirements: !ruby/object:Gem::Requirement
|
71
|
-
requirements:
|
72
|
-
- - "~>"
|
73
|
-
- !ruby/object:Gem::Version
|
74
|
-
version: '10.0'
|
75
|
-
- !ruby/object:Gem::Dependency
|
76
|
-
name: rspec
|
77
|
-
requirement: !ruby/object:Gem::Requirement
|
78
|
-
requirements:
|
79
|
-
- - "~>"
|
80
|
-
- !ruby/object:Gem::Version
|
81
|
-
version: '3.0'
|
82
|
-
type: :development
|
83
|
-
prerelease: false
|
84
|
-
version_requirements: !ruby/object:Gem::Requirement
|
85
|
-
requirements:
|
86
|
-
- - "~>"
|
87
|
-
- !ruby/object:Gem::Version
|
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
50
|
requirements:
|
100
51
|
- - ">="
|
101
52
|
- !ruby/object:Gem::Version
|
102
|
-
version:
|
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'
|
53
|
+
version: 12.3.3
|
110
54
|
type: :development
|
111
55
|
prerelease: false
|
112
56
|
version_requirements: !ruby/object:Gem::Requirement
|
113
57
|
requirements:
|
114
58
|
- - ">="
|
115
59
|
- !ruby/object:Gem::Version
|
116
|
-
version:
|
60
|
+
version: 12.3.3
|
117
61
|
description: An extension for Lograge to log SQL queries
|
118
62
|
email:
|
119
63
|
- giuffrida.mattia@gmail.com
|
@@ -121,22 +65,13 @@ executables: []
|
|
121
65
|
extensions: []
|
122
66
|
extra_rdoc_files: []
|
123
67
|
files:
|
124
|
-
- ".gitignore"
|
125
|
-
- ".rspec"
|
126
|
-
- ".rubocop.yml"
|
127
|
-
- ".travis.yml"
|
128
|
-
- Gemfile
|
129
68
|
- README.md
|
130
69
|
- Rakefile
|
131
|
-
-
|
132
|
-
- bin/setup
|
133
|
-
- gemfiles/lograge10.gemfile
|
134
|
-
- gemfiles/lograge11.gemfile
|
70
|
+
- lib/lograge/active_record_log_subscriber.rb
|
135
71
|
- lib/lograge/sql.rb
|
136
72
|
- lib/lograge/sql/extension.rb
|
137
73
|
- lib/lograge/sql/railtie.rb
|
138
74
|
- lib/lograge/sql/version.rb
|
139
|
-
- lograge-sql.gemspec
|
140
75
|
homepage: https://github.com/iMacTia/lograge-sql
|
141
76
|
licenses:
|
142
77
|
- MIT
|
@@ -149,15 +84,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
149
84
|
requirements:
|
150
85
|
- - ">="
|
151
86
|
- !ruby/object:Gem::Version
|
152
|
-
version:
|
87
|
+
version: 2.5.0
|
153
88
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
89
|
requirements:
|
155
90
|
- - ">="
|
156
91
|
- !ruby/object:Gem::Version
|
157
92
|
version: '0'
|
158
93
|
requirements: []
|
159
|
-
|
160
|
-
rubygems_version: 2.7.7
|
94
|
+
rubygems_version: 3.1.6
|
161
95
|
signing_key:
|
162
96
|
specification_version: 4
|
163
97
|
summary: An extension for Lograge to log SQL queries
|
data/.gitignore
DELETED
data/.rspec
DELETED
data/.rubocop.yml
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
require:
|
2
|
-
- rubocop-performance
|
3
|
-
|
4
|
-
AllCops:
|
5
|
-
DisplayCopNames: true
|
6
|
-
DisplayStyleGuide: true
|
7
|
-
TargetRubyVersion: 2.3
|
8
|
-
Exclude:
|
9
|
-
- gemfiles/vendor/bundle/**/*
|
10
|
-
|
11
|
-
Metrics/BlockLength:
|
12
|
-
Exclude:
|
13
|
-
- spec/**/*.rb
|
14
|
-
|
15
|
-
Metrics/LineLength:
|
16
|
-
Max: 120
|
17
|
-
Exclude:
|
18
|
-
- spec/**/*.rb
|
19
|
-
|
20
|
-
Style/Documentation:
|
21
|
-
Exclude:
|
22
|
-
- 'spec/**/*'
|
data/.travis.yml
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
cache: bundler
|
3
|
-
rvm:
|
4
|
-
- 2.4
|
5
|
-
- 2.5
|
6
|
-
- 2.6
|
7
|
-
- ruby-head
|
8
|
-
gemfile:
|
9
|
-
- gemfiles/lograge10.gemfile
|
10
|
-
- gemfiles/lograge11.gemfile
|
11
|
-
before_install:
|
12
|
-
- gem update --system
|
13
|
-
- gem install bundler
|
14
|
-
jobs:
|
15
|
-
include:
|
16
|
-
- stage: linting
|
17
|
-
rvm: 2.6
|
18
|
-
gemfile: gemfiles/lograge11.gemfile # Only run on 1 gemfile
|
19
|
-
install: true # Do not bundle install
|
20
|
-
script: gem install rubocop rubocop-performance --no-document && rubocop
|
21
|
-
stages:
|
22
|
-
- linting
|
23
|
-
- test
|
24
|
-
deploy:
|
25
|
-
provider: rubygems
|
26
|
-
api_key:
|
27
|
-
secure: xlc4BM+5ljo4cO2FC71KbhbVGVYd3NMxhZPat/Y37vo6b5/I01D+Z+K84azMvhIZa+O17cA56FGqT6P0XYfcjZVnYzixpyRlbffKBGNPcIFj2UklWk2BDOojezHPEQnbR2f0jE2+8jHtAb9qyoBTbTlvsW3+svd76+53TxMW1PgGF9+1xdtlEumF1q+IYRL+5TzDLk9GyQ+3RmVd9KBVvQIxxUpn4COJohmQWnv98ZzluX4I/QUt3k4o+etUINPewyg3S+VNP0u+K9HGkY3TL8OpUbCS3Syr3OydwzgpXIBlW+kWVez5/qZn3pd6oSpNEUF9Mh3NhaVsDacFSh6XgGNgww+isazyAROsledK2GsEOH0Hi6gpia/Ny5cD5TFAiGshMcUIb2K4roI3AW9kJ2e59hoC+QvPy64IybO/dhaKcxwX8F4qq3Fk/8EzQV5eOTq0Iai5aYNJaGZUqHV/X4DiMwDk/JoyQVYE+2CMF/PlZIFV4LuegDArVXYh5w3Qo9vYDfNp7Hfv0w5XgpEqAhk+Dabl+BlVhzSM/Cf28i6OVAhLURnGMNKhQEi3/4EusaM/cOQlM5QKWweAPfOwDKMFUoj9+Rtr0FfSyNzerG9dlGuzEKOlqq+XuOQ7RfDUV4+bn2PwbYo5XwMKz1Y8FWUZTz6l14miaw8Yq7U0GU8=
|
28
|
-
gem: lograge-sql
|
29
|
-
on:
|
30
|
-
tags: true
|
31
|
-
repo: iMacTia/lograge-sql
|
32
|
-
rvm: 2.6
|
33
|
-
|
data/Gemfile
DELETED
data/bin/console
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
require 'bundler/setup'
|
5
|
-
require 'lograge/sql'
|
6
|
-
|
7
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
-
# with your gem easier. You can also use a different console, if you like.
|
9
|
-
|
10
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
-
# require "pry"
|
12
|
-
# Pry.start
|
13
|
-
|
14
|
-
require 'irb'
|
15
|
-
IRB.start
|
data/bin/setup
DELETED
data/gemfiles/lograge10.gemfile
DELETED
data/gemfiles/lograge11.gemfile
DELETED
data/lograge-sql.gemspec
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
lib = File.expand_path('lib', __dir__)
|
4
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
-
require 'lograge/sql/version'
|
6
|
-
|
7
|
-
Gem::Specification.new do |spec|
|
8
|
-
spec.name = 'lograge-sql'
|
9
|
-
spec.version = Lograge::Sql::VERSION
|
10
|
-
spec.authors = ['Mattia Giuffrida']
|
11
|
-
spec.email = ['giuffrida.mattia@gmail.com']
|
12
|
-
|
13
|
-
spec.summary = 'An extension for Lograge to log SQL queries'
|
14
|
-
spec.description = 'An extension for Lograge to log SQL queries'
|
15
|
-
spec.homepage = 'https://github.com/iMacTia/lograge-sql'
|
16
|
-
spec.license = 'MIT'
|
17
|
-
|
18
|
-
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
|
-
spec.bindir = 'exe'
|
20
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
-
spec.require_paths = ['lib']
|
22
|
-
|
23
|
-
spec.add_runtime_dependency 'activerecord', '>= 4', '< 7.0'
|
24
|
-
spec.add_runtime_dependency 'lograge', '~> 0.4'
|
25
|
-
|
26
|
-
spec.add_development_dependency 'bundler', '~> 2.0'
|
27
|
-
spec.add_development_dependency 'rake', '~> 10.0'
|
28
|
-
spec.add_development_dependency 'rspec', '~> 3.0'
|
29
|
-
spec.add_development_dependency 'rubocop'
|
30
|
-
spec.add_development_dependency 'rubocop-performance'
|
31
|
-
end
|