debug_logging 1.0.15 → 3.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 +5 -5
- data/.rubocop.yml +99 -0
- data/.rubocop_todo.yml +133 -0
- data/.travis.yml +34 -5
- data/Gemfile +8 -2
- data/README.md +94 -39
- data/Rakefile +5 -3
- data/bin/console +4 -3
- data/debug_logging.gemspec +24 -20
- data/lib/debug_logging.rb +47 -11
- data/lib/debug_logging/active_support_notifications.rb +6 -0
- data/lib/debug_logging/argument_printer.rb +46 -33
- data/lib/debug_logging/class_logger.rb +4 -2
- data/lib/debug_logging/class_notifier.rb +47 -0
- data/lib/debug_logging/configuration.rb +64 -48
- data/lib/debug_logging/instance_logger.rb +5 -0
- data/lib/debug_logging/instance_logger_modulizer.rb +4 -2
- data/lib/debug_logging/instance_notifier.rb +18 -0
- data/lib/debug_logging/instance_notifier_modulizer.rb +51 -0
- data/lib/debug_logging/log_subscriber.rb +35 -0
- data/lib/debug_logging/version.rb +3 -1
- data/lib/simple_debug_logging.rb +7 -5
- metadata +88 -34
@@ -1,11 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module DebugLogging
|
2
4
|
class InstanceLogger < Module
|
3
5
|
def initialize(i_methods: nil, config: nil)
|
6
|
+
super()
|
4
7
|
@config = config
|
5
8
|
@instance_methods_to_log = Array(i_methods) if i_methods
|
6
9
|
end
|
10
|
+
|
7
11
|
def included(base)
|
8
12
|
return unless @instance_methods_to_log
|
13
|
+
|
9
14
|
base.send(:include, ArgumentPrinter)
|
10
15
|
instance_method_logger = DebugLogging::InstanceLoggerModulizer.to_mod(methods_to_log: @instance_methods_to_log, config: @config)
|
11
16
|
base.send(:prepend, instance_method_logger)
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module DebugLogging
|
2
4
|
module InstanceLoggerModulizer
|
3
5
|
def self.to_mod(methods_to_log: nil, config: nil)
|
@@ -10,7 +12,7 @@ module DebugLogging
|
|
10
12
|
proxy
|
11
13
|
else
|
12
14
|
proxy = if config
|
13
|
-
Configuration.new(**
|
15
|
+
Configuration.new(**self.class.debug_config.to_hash.merge(config))
|
14
16
|
else
|
15
17
|
self.class.debug_config
|
16
18
|
end
|
@@ -18,7 +20,7 @@ module DebugLogging
|
|
18
20
|
instance_variable_set(DebugLogging::Configuration.config_pointer('i', method_to_log), proxy)
|
19
21
|
proxy
|
20
22
|
end
|
21
|
-
log_prefix = self.class.debug_invocation_to_s(klass: self.class.to_s, separator:
|
23
|
+
log_prefix = self.class.debug_invocation_to_s(klass: self.class.to_s, separator: '#', method_to_log: method_to_log, config_proxy: config_proxy)
|
22
24
|
invocation_id = self.class.debug_invocation_id_to_s(args: args, config_proxy: config_proxy)
|
23
25
|
config_proxy.log do
|
24
26
|
signature = self.class.debug_signature_to_s(args: args, config_proxy: config_proxy)
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DebugLogging
|
4
|
+
class InstanceNotifier < Module
|
5
|
+
def initialize(i_methods: nil)
|
6
|
+
super()
|
7
|
+
@instance_methods_to_notify = Array(i_methods) if i_methods
|
8
|
+
end
|
9
|
+
|
10
|
+
def included(base)
|
11
|
+
return unless @instance_methods_to_notify
|
12
|
+
|
13
|
+
base.send(:include, ArgumentPrinter)
|
14
|
+
instance_method_notifier = DebugLogging::InstanceNotifierModulizer.to_mod(methods_to_notify: @instance_methods_to_notify)
|
15
|
+
base.send(:prepend, instance_method_notifier)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DebugLogging
|
4
|
+
module InstanceNotifierModulizer
|
5
|
+
def self.to_mod(methods_to_notify: nil)
|
6
|
+
Module.new do
|
7
|
+
Array(methods_to_notify).each do |method_to_notify|
|
8
|
+
# method name must be a symbol
|
9
|
+
payload = method_to_notify.is_a?(Array) && method_to_notify.last.is_a?(Hash) && method_to_notify.pop || {}
|
10
|
+
if method_to_notify.is_a?(Array)
|
11
|
+
method_to_notify = method_to_notify.first&.to_sym
|
12
|
+
else
|
13
|
+
method_to_notify.to_sym
|
14
|
+
end
|
15
|
+
config_proxy = nil
|
16
|
+
define_method(method_to_notify) do |*args, &block|
|
17
|
+
config_proxy = if (proxy = instance_variable_get(DebugLogging::Configuration.config_pointer('i', method_to_notify)))
|
18
|
+
proxy
|
19
|
+
else
|
20
|
+
proxy = if !payload.empty?
|
21
|
+
Configuration.new(**self.class.debug_config.to_hash.merge(payload))
|
22
|
+
else
|
23
|
+
self.class.debug_config
|
24
|
+
end
|
25
|
+
proxy.register(method_to_notify)
|
26
|
+
instance_variable_set(DebugLogging::Configuration.config_pointer('i', method_to_notify), proxy)
|
27
|
+
proxy
|
28
|
+
end
|
29
|
+
if payload.key?(:instance_variables)
|
30
|
+
payload[:instance_variables].each do |k|
|
31
|
+
payload[k] = instance_variable_get("@#{k}") if instance_variable_get("@#{k}")
|
32
|
+
end
|
33
|
+
payload.delete(:instance_variables)
|
34
|
+
end
|
35
|
+
ActiveSupport::Notifications.instrument(
|
36
|
+
self.class.debug_event_name_to_s(method_to_notify: method_to_notify), { args: args }.merge(payload)
|
37
|
+
) do
|
38
|
+
super(*args, &block)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
ActiveSupport::Notifications.subscribe(/log/) do |*args|
|
43
|
+
config_proxy&.log do
|
44
|
+
DebugLogging::LogSubscriber.log_event(ActiveSupport::Notifications::Event.new(*args))
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/log_subscriber'
|
4
|
+
|
5
|
+
module DebugLogging
|
6
|
+
class LogSubscriber < ActiveSupport::LogSubscriber
|
7
|
+
class << self
|
8
|
+
attr_accessor :event
|
9
|
+
end
|
10
|
+
attach_to :log
|
11
|
+
|
12
|
+
EVENT_FORMAT_STRING = '%<name>s (%<duration>.3f secs) start=%<time>s end=%<end>s payload=%<payload>s'
|
13
|
+
|
14
|
+
def self.log_event(event)
|
15
|
+
@event = event
|
16
|
+
if event.payload && event.payload[:exception_object]
|
17
|
+
exception = event.payload[:exception_object]
|
18
|
+
"#{event.name} [ERROR] : \n#{exception.class} : #{exception.message}\n" + exception.backtrace.join("\n")
|
19
|
+
end
|
20
|
+
format(EVENT_FORMAT_STRING, event_to_format_options(event))
|
21
|
+
end
|
22
|
+
|
23
|
+
# @param [ActiveSupport::Notifications::Event]
|
24
|
+
# @return [Hash]
|
25
|
+
def self.event_to_format_options(event)
|
26
|
+
{
|
27
|
+
name: event.name,
|
28
|
+
duration: Rational(event.duration, 1000).to_f,
|
29
|
+
time: event.time,
|
30
|
+
end: event.end,
|
31
|
+
payload: event.payload
|
32
|
+
}
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/simple_debug_logging.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Simpler version of what the sibling DebugLogging library does. Included as a bauble.
|
2
4
|
#
|
3
5
|
############# THIS IS A BAUBLE
|
4
6
|
############# FOR EXAMINING SEVERAL OF THE WONDERS OF RUBY
|
5
7
|
############# TO ACCOMPLISH SOMETHING PRACTICAL
|
6
|
-
############# For a more robust implementation use the gem debug_logging itself,
|
8
|
+
############# For a more robust implementation use the gem debug_logging itself,
|
7
9
|
############# which makes use of these same principles.
|
8
10
|
#
|
9
11
|
# Automatically log Class.method(arguments) as they are called at runtime (instance or singleton)!
|
@@ -19,8 +21,6 @@
|
|
19
21
|
# logged :a_class_method
|
20
22
|
# end
|
21
23
|
#
|
22
|
-
# Make sure you have the latest debug_logging gem (>= 1.0.10) installed for this to work
|
23
|
-
#
|
24
24
|
# In an irb session:
|
25
25
|
# >> require_relative 'unobtrusively_logged'
|
26
26
|
# => true
|
@@ -39,8 +39,10 @@ require 'benchmark'
|
|
39
39
|
|
40
40
|
class SimpleDebugLogging < Module
|
41
41
|
def initialize(i_methods: nil)
|
42
|
+
super()
|
42
43
|
@instance_methods_to_log = Array(i_methods) if i_methods
|
43
44
|
end
|
45
|
+
|
44
46
|
def included(base)
|
45
47
|
instance_method_logger = InstanceMethodLoggerModulizer.to_mod(@instance_methods_to_log)
|
46
48
|
base.send(:prepend, instance_method_logger)
|
@@ -54,7 +56,7 @@ class SimpleDebugLogging < Module
|
|
54
56
|
define_method(method_to_log.to_sym) do |*args|
|
55
57
|
method_return_value = nil
|
56
58
|
invocation_id = " ~#{args.object_id}@#{Time.now.to_i}~" if args
|
57
|
-
puts "#{self}.#{method_to_log}(#{args.map
|
59
|
+
puts "#{self}.#{method_to_log}(#{args.map(&:inspect).join(', ')})#{invocation_id}"
|
58
60
|
elapsed = Benchmark.realtime do
|
59
61
|
method_return_value = original_method.call(*args)
|
60
62
|
end
|
@@ -72,7 +74,7 @@ class SimpleDebugLogging < Module
|
|
72
74
|
define_method(method_to_log.to_sym) do |*args, &block|
|
73
75
|
method_return_value = nil
|
74
76
|
invocation_id = " ~#{args.object_id}@#{Time.now.to_i}~" if args
|
75
|
-
puts "#{self.class}##{method_to_log}(#{args.map
|
77
|
+
puts "#{self.class}##{method_to_log}(#{args.map(&:inspect).join(', ')})#{invocation_id}"
|
76
78
|
elapsed = Benchmark.realtime do
|
77
79
|
method_return_value = super(*args, &block)
|
78
80
|
end
|
metadata
CHANGED
@@ -1,113 +1,161 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: debug_logging
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 3.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Boling
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-10-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0
|
19
|
+
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: activesupport
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5.2'
|
31
34
|
- - ">="
|
32
35
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
36
|
+
version: 5.2.4.4
|
34
37
|
type: :development
|
35
38
|
prerelease: false
|
36
39
|
version_requirements: !ruby/object:Gem::Requirement
|
37
40
|
requirements:
|
41
|
+
- - "~>"
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '5.2'
|
38
44
|
- - ">="
|
39
45
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
46
|
+
version: 5.2.4.4
|
41
47
|
- !ruby/object:Gem::Dependency
|
42
48
|
name: bundler
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
44
50
|
requirements:
|
45
|
-
- - "
|
51
|
+
- - ">="
|
46
52
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
53
|
+
version: '2'
|
48
54
|
type: :development
|
49
55
|
prerelease: false
|
50
56
|
version_requirements: !ruby/object:Gem::Requirement
|
51
57
|
requirements:
|
52
|
-
- - "
|
58
|
+
- - ">="
|
53
59
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
60
|
+
version: '2'
|
55
61
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
62
|
+
name: byebug
|
57
63
|
requirement: !ruby/object:Gem::Requirement
|
58
64
|
requirements:
|
59
|
-
- - "
|
65
|
+
- - ">="
|
60
66
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
67
|
+
version: '11'
|
62
68
|
type: :development
|
63
69
|
prerelease: false
|
64
70
|
version_requirements: !ruby/object:Gem::Requirement
|
65
71
|
requirements:
|
66
|
-
- - "
|
72
|
+
- - ">="
|
67
73
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
74
|
+
version: '11'
|
69
75
|
- !ruby/object:Gem::Dependency
|
70
76
|
name: rake
|
71
77
|
requirement: !ruby/object:Gem::Requirement
|
72
78
|
requirements:
|
73
|
-
- - "
|
79
|
+
- - ">="
|
74
80
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
81
|
+
version: '13'
|
76
82
|
type: :development
|
77
83
|
prerelease: false
|
78
84
|
version_requirements: !ruby/object:Gem::Requirement
|
79
85
|
requirements:
|
80
|
-
- - "
|
86
|
+
- - ">="
|
81
87
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
88
|
+
version: '13'
|
83
89
|
- !ruby/object:Gem::Dependency
|
84
90
|
name: rspec
|
85
91
|
requirement: !ruby/object:Gem::Requirement
|
86
92
|
requirements:
|
87
|
-
- - "
|
93
|
+
- - ">="
|
88
94
|
- !ruby/object:Gem::Version
|
89
|
-
version: '3
|
95
|
+
version: '3'
|
90
96
|
type: :development
|
91
97
|
prerelease: false
|
92
98
|
version_requirements: !ruby/object:Gem::Requirement
|
93
99
|
requirements:
|
94
|
-
- - "
|
100
|
+
- - ">="
|
95
101
|
- !ruby/object:Gem::Version
|
96
|
-
version: '3
|
102
|
+
version: '3'
|
97
103
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
104
|
+
name: rspec-pending_for
|
99
105
|
requirement: !ruby/object:Gem::Requirement
|
100
106
|
requirements:
|
101
|
-
- - "
|
107
|
+
- - ">="
|
102
108
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
109
|
+
version: '0'
|
104
110
|
type: :development
|
105
111
|
prerelease: false
|
106
112
|
version_requirements: !ruby/object:Gem::Requirement
|
107
113
|
requirements:
|
108
|
-
- - "
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: rubocop
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0.92'
|
124
|
+
type: :development
|
125
|
+
prerelease: false
|
126
|
+
version_requirements: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0.92'
|
131
|
+
- !ruby/object:Gem::Dependency
|
132
|
+
name: rubocop-rspec
|
133
|
+
requirement: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '1'
|
138
|
+
type: :development
|
139
|
+
prerelease: false
|
140
|
+
version_requirements: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - ">="
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '1'
|
145
|
+
- !ruby/object:Gem::Dependency
|
146
|
+
name: silent_stream
|
147
|
+
requirement: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '1'
|
152
|
+
type: :development
|
153
|
+
prerelease: false
|
154
|
+
version_requirements: !ruby/object:Gem::Requirement
|
155
|
+
requirements:
|
156
|
+
- - ">="
|
109
157
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
158
|
+
version: '1'
|
111
159
|
description: |2
|
112
160
|
|
113
161
|
Unobtrusive debug logging for Ruby. NO LITTERING.
|
@@ -121,6 +169,8 @@ files:
|
|
121
169
|
- ".coveralls.yml"
|
122
170
|
- ".gitignore"
|
123
171
|
- ".rspec"
|
172
|
+
- ".rubocop.yml"
|
173
|
+
- ".rubocop_todo.yml"
|
124
174
|
- ".travis.yml"
|
125
175
|
- Gemfile
|
126
176
|
- README.md
|
@@ -129,11 +179,16 @@ files:
|
|
129
179
|
- bin/setup
|
130
180
|
- debug_logging.gemspec
|
131
181
|
- lib/debug_logging.rb
|
182
|
+
- lib/debug_logging/active_support_notifications.rb
|
132
183
|
- lib/debug_logging/argument_printer.rb
|
133
184
|
- lib/debug_logging/class_logger.rb
|
185
|
+
- lib/debug_logging/class_notifier.rb
|
134
186
|
- lib/debug_logging/configuration.rb
|
135
187
|
- lib/debug_logging/instance_logger.rb
|
136
188
|
- lib/debug_logging/instance_logger_modulizer.rb
|
189
|
+
- lib/debug_logging/instance_notifier.rb
|
190
|
+
- lib/debug_logging/instance_notifier_modulizer.rb
|
191
|
+
- lib/debug_logging/log_subscriber.rb
|
137
192
|
- lib/debug_logging/version.rb
|
138
193
|
- lib/simple_debug_logging.rb
|
139
194
|
homepage: https://github.com/pboling/debug_logging
|
@@ -148,15 +203,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
148
203
|
requirements:
|
149
204
|
- - ">="
|
150
205
|
- !ruby/object:Gem::Version
|
151
|
-
version: 2.
|
206
|
+
version: 2.4.0
|
152
207
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
153
208
|
requirements:
|
154
209
|
- - ">="
|
155
210
|
- !ruby/object:Gem::Version
|
156
211
|
version: '0'
|
157
212
|
requirements: []
|
158
|
-
|
159
|
-
rubygems_version: 2.6.12
|
213
|
+
rubygems_version: 3.1.4
|
160
214
|
signing_key:
|
161
215
|
specification_version: 4
|
162
216
|
summary: Drop-in debug logging useful when a call stack gets unruly
|