markdown_logging_proxy 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/dist/markdown_logging_proxy.rb +38 -28
- data/lib/markdown_logging_proxy/markdown_logger.rb +0 -14
- data/lib/markdown_logging_proxy/proxy.rb +2 -0
- data/lib/markdown_logging_proxy/tracer.rb +36 -14
- data/markdown_logging_proxy.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 215b4bc73f85cdb7ec9bfa2e3ef3b1efefa55a9d99c34f36007788c798dcbcc0
|
4
|
+
data.tar.gz: 391123e09db062038d9e4e4ef3aa2a98f15dc07a7727ede676d6a51d7c5cf532
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3119ffa9798cf92d8010df9d20738eaf1c7e782de72b40709aba08066270811b31b119ada4ba977e4af67fc5f37da6d455a01afd81ab0a8a62fe944587323c58
|
7
|
+
data.tar.gz: 6171e82b3677b73c9fa83753a9a21927625427a344b77e07f6285f5090bc1eff156c51504f74310a33bf7fef1bd36bfab4c191423369715b0427d7018b0a475e
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -4,20 +4,6 @@ require 'pp'
|
|
4
4
|
require 'time'
|
5
5
|
module MarkdownLoggingProxy
|
6
6
|
class MarkdownLogger
|
7
|
-
def self.inspect_object(object, show_id = true)
|
8
|
-
[
|
9
|
-
'```ruby',
|
10
|
-
("# #{id_object(object)}" if show_id),
|
11
|
-
object.pretty_inspect.chomp,
|
12
|
-
'```'
|
13
|
-
].compact.join("\n")
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.id_object(object)
|
17
|
-
# #<Object:0x00007f5a0919e140>
|
18
|
-
"`#<#{object.class}:0x#{object.object_id.to_s(16)}>`"
|
19
|
-
end
|
20
|
-
|
21
7
|
def self.build(location, **options)
|
22
8
|
return location if location.is_a?(MarkdownLogger)
|
23
9
|
new(location, **options)
|
@@ -94,6 +80,7 @@ module MarkdownLoggingProxy
|
|
94
80
|
target: nil,
|
95
81
|
location: STDOUT,
|
96
82
|
backtrace: true, # regex/true/false backtrace control
|
83
|
+
inspect_method: :pretty_inspect,
|
97
84
|
ignore: [], # methods we shouldn't log/proxy
|
98
85
|
proxy_response: [], # methods we should return a proxy for
|
99
86
|
overwrite: DEFAULT_OVERWRITES
|
@@ -104,6 +91,7 @@ module MarkdownLoggingProxy
|
|
104
91
|
target: @target,
|
105
92
|
proxy: self,
|
106
93
|
logger: @logger,
|
94
|
+
inspect_method: inspect_method,
|
107
95
|
ignore: ignore,
|
108
96
|
proxy_response: proxy_response,
|
109
97
|
proxy_options: {
|
@@ -125,18 +113,20 @@ module MarkdownLoggingProxy
|
|
125
113
|
end
|
126
114
|
module MarkdownLoggingProxy
|
127
115
|
class Tracer
|
128
|
-
attr_reader :target, :logger, :ignore, :proxy
|
116
|
+
attr_reader :target, :logger, :ignore, :proxy, :inspect_method
|
129
117
|
|
130
118
|
def initialize(
|
131
119
|
target:,
|
132
120
|
proxy:,
|
133
121
|
logger: nil,
|
122
|
+
inspect_method: :pretty_inspect,
|
134
123
|
ignore: [],
|
135
124
|
proxy_response: [],
|
136
125
|
proxy_options: {}
|
137
126
|
)
|
138
127
|
@target = target
|
139
128
|
@logger = logger
|
129
|
+
@inspect_method = inspect_method
|
140
130
|
@ignore = ignore
|
141
131
|
@proxy_response = proxy_response
|
142
132
|
@proxy_options = proxy_options
|
@@ -161,16 +151,36 @@ module MarkdownLoggingProxy
|
|
161
151
|
@ignore.member?(meth)
|
162
152
|
end
|
163
153
|
|
154
|
+
def inspect_object(obj, show_id: true)
|
155
|
+
obj_str =
|
156
|
+
case inspect_method
|
157
|
+
when :inspect then obj.inspect
|
158
|
+
when :object_id then object_id(obj)
|
159
|
+
when :pretty_inpect
|
160
|
+
[obj.pretty_inspect.chomp].tap do |lines|
|
161
|
+
lines.prepend "# #{object_id(obj)}" if show_id
|
162
|
+
end.join("\n")
|
163
|
+
else
|
164
|
+
obj.send(inspect_method)
|
165
|
+
end
|
166
|
+
['```ruby', obj_str, '```'].join("\n")
|
167
|
+
end
|
168
|
+
|
169
|
+
def id_object(object)
|
170
|
+
# #<Object:0xe140>
|
171
|
+
"`#<#{object.class}:0x#{object.object_id.to_s(16)}>`"
|
172
|
+
end
|
173
|
+
|
164
174
|
private
|
165
175
|
|
166
176
|
def log_call_signature(meth, args, &blk)
|
167
177
|
return if ignore.member?(meth)
|
168
178
|
logger.log :info, 1, <<~MSG.chomp
|
169
|
-
Calling `#{meth}` on #{
|
179
|
+
Calling `#{meth}` on #{id_object(target)}
|
170
180
|
|
171
181
|
Arguments:
|
172
182
|
|
173
|
-
#{
|
183
|
+
#{inspect_object(args, show_id: false)}
|
174
184
|
|
175
185
|
Block given? #{block_given? ? 'Yes' : 'No'}
|
176
186
|
#{logger.inspect_backtrace}
|
@@ -184,15 +194,16 @@ module MarkdownLoggingProxy
|
|
184
194
|
logger.log :info, 3, <<~MSG.chomp
|
185
195
|
Returning proxied response to `#{meth}`
|
186
196
|
|
187
|
-
Proxy from `#{meth}` on #{
|
197
|
+
Proxy from `#{meth}` on #{id_object(target)}
|
188
198
|
|
189
199
|
Proxy for:
|
190
200
|
|
191
|
-
#{
|
201
|
+
#{inspect_object(response)}
|
192
202
|
MSG
|
193
203
|
Proxy.new(**@proxy_options.merge(
|
194
204
|
target: response,
|
195
205
|
location: logger,
|
206
|
+
inspect_method: inspect_method,
|
196
207
|
proxy_response: @proxy_response,
|
197
208
|
ignore: @ignore,
|
198
209
|
))
|
@@ -200,21 +211,20 @@ module MarkdownLoggingProxy
|
|
200
211
|
|
201
212
|
def log_and_proxy_block(meth, blk)
|
202
213
|
return if blk.nil?
|
203
|
-
|
204
|
-
target_ref = self.target
|
214
|
+
tracer = self
|
205
215
|
proc do |*args|
|
206
|
-
|
207
|
-
Yield to block in `#{meth}` on #{
|
216
|
+
tracer.logger.log :info, 2, <<~MSG.chomp
|
217
|
+
Yield to block in `#{meth}` on #{tracer.id_object(tracer.target)}
|
208
218
|
|
209
219
|
Arguments:
|
210
220
|
|
211
|
-
#{
|
221
|
+
#{tracer.inspect_object(args, show_id: false)}
|
212
222
|
MSG
|
213
223
|
instance_exec(*args, &blk).tap do |response|
|
214
|
-
|
224
|
+
tracer.logger.log :info, 3, <<~MSG.chomp
|
215
225
|
Response from block in `#{meth}`
|
216
226
|
|
217
|
-
#{
|
227
|
+
#{tracer.inspect_object(response)}
|
218
228
|
MSG
|
219
229
|
end
|
220
230
|
end
|
@@ -226,7 +236,7 @@ module MarkdownLoggingProxy
|
|
226
236
|
|
227
237
|
Type: #{error.class}
|
228
238
|
|
229
|
-
#{
|
239
|
+
#{inspect_object(error)}
|
230
240
|
MSG
|
231
241
|
raise error
|
232
242
|
end
|
@@ -236,7 +246,7 @@ module MarkdownLoggingProxy
|
|
236
246
|
logger.log :info, 2, <<~MSG.chomp
|
237
247
|
`#{meth}` response
|
238
248
|
|
239
|
-
#{
|
249
|
+
#{inspect_object(response)}
|
240
250
|
MSG
|
241
251
|
end
|
242
252
|
end
|
@@ -1,19 +1,5 @@
|
|
1
1
|
module MarkdownLoggingProxy
|
2
2
|
class MarkdownLogger
|
3
|
-
def self.inspect_object(object, show_id = true)
|
4
|
-
[
|
5
|
-
'```ruby',
|
6
|
-
("# #{id_object(object)}" if show_id),
|
7
|
-
object.pretty_inspect.chomp,
|
8
|
-
'```'
|
9
|
-
].compact.join("\n")
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.id_object(object)
|
13
|
-
# #<Object:0x00007f5a0919e140>
|
14
|
-
"`#<#{object.class}:0x#{object.object_id.to_s(16)}>`"
|
15
|
-
end
|
16
|
-
|
17
3
|
def self.build(location, **options)
|
18
4
|
return location if location.is_a?(MarkdownLogger)
|
19
5
|
new(location, **options)
|
@@ -8,6 +8,7 @@ module MarkdownLoggingProxy
|
|
8
8
|
target: nil,
|
9
9
|
location: STDOUT,
|
10
10
|
backtrace: true, # regex/true/false backtrace control
|
11
|
+
inspect_method: :pretty_inspect,
|
11
12
|
ignore: [], # methods we shouldn't log/proxy
|
12
13
|
proxy_response: [], # methods we should return a proxy for
|
13
14
|
overwrite: DEFAULT_OVERWRITES
|
@@ -18,6 +19,7 @@ module MarkdownLoggingProxy
|
|
18
19
|
target: @target,
|
19
20
|
proxy: self,
|
20
21
|
logger: @logger,
|
22
|
+
inspect_method: inspect_method,
|
21
23
|
ignore: ignore,
|
22
24
|
proxy_response: proxy_response,
|
23
25
|
proxy_options: {
|
@@ -1,17 +1,19 @@
|
|
1
1
|
module MarkdownLoggingProxy
|
2
2
|
class Tracer
|
3
|
-
attr_reader :target, :logger, :ignore, :proxy
|
3
|
+
attr_reader :target, :logger, :ignore, :proxy, :inspect_method
|
4
4
|
|
5
5
|
def initialize(
|
6
6
|
target:,
|
7
7
|
proxy:,
|
8
8
|
logger: nil,
|
9
|
+
inspect_method: :pretty_inspect,
|
9
10
|
ignore: [],
|
10
11
|
proxy_response: [],
|
11
12
|
proxy_options: {}
|
12
13
|
)
|
13
14
|
@target = target
|
14
15
|
@logger = logger
|
16
|
+
@inspect_method = inspect_method
|
15
17
|
@ignore = ignore
|
16
18
|
@proxy_response = proxy_response
|
17
19
|
@proxy_options = proxy_options
|
@@ -36,16 +38,36 @@ module MarkdownLoggingProxy
|
|
36
38
|
@ignore.member?(meth)
|
37
39
|
end
|
38
40
|
|
41
|
+
def inspect_object(obj, show_id: true)
|
42
|
+
obj_str =
|
43
|
+
case inspect_method
|
44
|
+
when :inspect then obj.inspect
|
45
|
+
when :object_id then object_id(obj)
|
46
|
+
when :pretty_inpect
|
47
|
+
[obj.pretty_inspect.chomp].tap do |lines|
|
48
|
+
lines.prepend "# #{object_id(obj)}" if show_id
|
49
|
+
end.join("\n")
|
50
|
+
else
|
51
|
+
obj.send(inspect_method)
|
52
|
+
end
|
53
|
+
['```ruby', obj_str, '```'].join("\n")
|
54
|
+
end
|
55
|
+
|
56
|
+
def id_object(object)
|
57
|
+
# #<Object:0xe140>
|
58
|
+
"`#<#{object.class}:0x#{object.object_id.to_s(16)}>`"
|
59
|
+
end
|
60
|
+
|
39
61
|
private
|
40
62
|
|
41
63
|
def log_call_signature(meth, args, &blk)
|
42
64
|
return if ignore.member?(meth)
|
43
65
|
logger.log :info, 1, <<~MSG.chomp
|
44
|
-
Calling `#{meth}` on #{
|
66
|
+
Calling `#{meth}` on #{id_object(target)}
|
45
67
|
|
46
68
|
Arguments:
|
47
69
|
|
48
|
-
#{
|
70
|
+
#{inspect_object(args, show_id: false)}
|
49
71
|
|
50
72
|
Block given? #{block_given? ? 'Yes' : 'No'}
|
51
73
|
#{logger.inspect_backtrace}
|
@@ -59,15 +81,16 @@ module MarkdownLoggingProxy
|
|
59
81
|
logger.log :info, 3, <<~MSG.chomp
|
60
82
|
Returning proxied response to `#{meth}`
|
61
83
|
|
62
|
-
Proxy from `#{meth}` on #{
|
84
|
+
Proxy from `#{meth}` on #{id_object(target)}
|
63
85
|
|
64
86
|
Proxy for:
|
65
87
|
|
66
|
-
#{
|
88
|
+
#{inspect_object(response)}
|
67
89
|
MSG
|
68
90
|
Proxy.new(**@proxy_options.merge(
|
69
91
|
target: response,
|
70
92
|
location: logger,
|
93
|
+
inspect_method: inspect_method,
|
71
94
|
proxy_response: @proxy_response,
|
72
95
|
ignore: @ignore,
|
73
96
|
))
|
@@ -75,21 +98,20 @@ module MarkdownLoggingProxy
|
|
75
98
|
|
76
99
|
def log_and_proxy_block(meth, blk)
|
77
100
|
return if blk.nil?
|
78
|
-
|
79
|
-
target_ref = self.target
|
101
|
+
tracer = self
|
80
102
|
proc do |*args|
|
81
|
-
|
82
|
-
Yield to block in `#{meth}` on #{
|
103
|
+
tracer.logger.log :info, 2, <<~MSG.chomp
|
104
|
+
Yield to block in `#{meth}` on #{tracer.id_object(tracer.target)}
|
83
105
|
|
84
106
|
Arguments:
|
85
107
|
|
86
|
-
#{
|
108
|
+
#{tracer.inspect_object(args, show_id: false)}
|
87
109
|
MSG
|
88
110
|
instance_exec(*args, &blk).tap do |response|
|
89
|
-
|
111
|
+
tracer.logger.log :info, 3, <<~MSG.chomp
|
90
112
|
Response from block in `#{meth}`
|
91
113
|
|
92
|
-
#{
|
114
|
+
#{tracer.inspect_object(response)}
|
93
115
|
MSG
|
94
116
|
end
|
95
117
|
end
|
@@ -101,7 +123,7 @@ module MarkdownLoggingProxy
|
|
101
123
|
|
102
124
|
Type: #{error.class}
|
103
125
|
|
104
|
-
#{
|
126
|
+
#{inspect_object(error)}
|
105
127
|
MSG
|
106
128
|
raise error
|
107
129
|
end
|
@@ -111,7 +133,7 @@ module MarkdownLoggingProxy
|
|
111
133
|
logger.log :info, 2, <<~MSG.chomp
|
112
134
|
`#{meth}` response
|
113
135
|
|
114
|
-
#{
|
136
|
+
#{inspect_object(response)}
|
115
137
|
MSG
|
116
138
|
end
|
117
139
|
end
|