spring_onion 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/spring_onion.rb +1 -0
- data/lib/spring_onion/config.rb +2 -2
- data/lib/spring_onion/explainer.rb +10 -19
- data/lib/spring_onion/json_logger.rb +25 -0
- data/lib/spring_onion/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 54ea2a17b7ab30f6e646ed61b125dcc22e82cf304c946d26c70222a6e5a78341
|
4
|
+
data.tar.gz: af308c44d05e7b58048e5c29bd8f708a14d7067111210338ec52296ae9e00f16
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d5fcd164189c1a47126b009f0d058baffc306958cb2dcbd3bbf8e0f0bd4d54f49b9f862204b0d46bb4f68e44cd24257a2f62dced99f93b900d620f7871f2cc4
|
7
|
+
data.tar.gz: 0cae3be0dc5e774d092b3e2624bc943604dc8a0aac30dadf645a86f736f13f80978d0ec5a4a5bf595c7eff150f047f79a95769ab9d344bc15917d2ca4dd9b0c1
|
data/Gemfile.lock
CHANGED
data/lib/spring_onion.rb
CHANGED
data/lib/spring_onion/config.rb
CHANGED
@@ -60,9 +60,9 @@ module SpringOnion
|
|
60
60
|
end
|
61
61
|
|
62
62
|
@logger = Logger.new($stdout).tap do |logger|
|
63
|
-
logger.formatter = lambda
|
63
|
+
logger.formatter = lambda do |severity, datetime, _progname, msg|
|
64
64
|
"\n#{self}\t#{severity}\t#{datetime}\t#{msg}\n"
|
65
|
-
|
65
|
+
end
|
66
66
|
end
|
67
67
|
|
68
68
|
@trace_len = 3
|
@@ -19,7 +19,7 @@ module SpringOnion
|
|
19
19
|
|
20
20
|
exp = conn.query("EXPLAIN #{sql}", as: :hash).to_a
|
21
21
|
exp.each { |r| r.delete('id') }
|
22
|
-
|
22
|
+
_validate_explain(exp, sql, trace)
|
23
23
|
end
|
24
24
|
end
|
25
25
|
rescue StandardError => e
|
@@ -29,35 +29,26 @@ module SpringOnion
|
|
29
29
|
yield
|
30
30
|
end
|
31
31
|
|
32
|
-
def
|
32
|
+
def _validate_explain(exp, sql, trace)
|
33
33
|
warnings = SpringOnion.warnings
|
34
|
-
|
34
|
+
warning_names_by_index = {}
|
35
35
|
|
36
36
|
exp.each_with_index do |row, i|
|
37
37
|
warning_names = warnings.select do |_name, validator|
|
38
38
|
validator.call(row)
|
39
39
|
end.keys
|
40
40
|
|
41
|
-
|
41
|
+
warning_names_by_index[i] = warning_names unless warning_names.empty?
|
42
42
|
end
|
43
43
|
|
44
|
-
return if
|
44
|
+
return if warning_names_by_index.empty?
|
45
45
|
|
46
|
-
|
46
|
+
SpringOnion::JsonLogger.log(
|
47
47
|
sql: sql,
|
48
|
-
explain: exp
|
49
|
-
warnings:
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
line = if SpringOnion.json_pretty
|
54
|
-
JSON.pretty_generate(h)
|
55
|
-
else
|
56
|
-
JSON.dump(h)
|
57
|
-
end
|
58
|
-
|
59
|
-
line = CodeRay.scan(line, :json).terminal if SpringOnion.color
|
60
|
-
SpringOnion.logger.info(line)
|
48
|
+
explain: exp,
|
49
|
+
warnings: warning_names_by_index,
|
50
|
+
trace: trace
|
51
|
+
)
|
61
52
|
end
|
62
53
|
end
|
63
54
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SpringOnion
|
4
|
+
module JsonLogger
|
5
|
+
module_function
|
6
|
+
|
7
|
+
def log(sql:, explain:, warnings:, trace:)
|
8
|
+
h = {
|
9
|
+
sql: sql,
|
10
|
+
explain: explain.each_with_index.map { |r, i| { line: i + 1 }.merge(r) },
|
11
|
+
warnings: warnings.transform_keys { |i| "line #{i + 1}" },
|
12
|
+
backtrace: trace.slice(0, SpringOnion.trace_len),
|
13
|
+
}
|
14
|
+
|
15
|
+
line = if SpringOnion.json_pretty
|
16
|
+
JSON.pretty_generate(h)
|
17
|
+
else
|
18
|
+
JSON.dump(h)
|
19
|
+
end
|
20
|
+
|
21
|
+
line = CodeRay.scan(line, :json).terminal if SpringOnion.color
|
22
|
+
SpringOnion.logger.info(line)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/spring_onion/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spring_onion
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- winebarrel
|
@@ -142,6 +142,7 @@ files:
|
|
142
142
|
- lib/spring_onion/config.rb
|
143
143
|
- lib/spring_onion/error.rb
|
144
144
|
- lib/spring_onion/explainer.rb
|
145
|
+
- lib/spring_onion/json_logger.rb
|
145
146
|
- lib/spring_onion/version.rb
|
146
147
|
- spring_onion.gemspec
|
147
148
|
homepage: https://github.com/winebarrel/spring_onion
|