debug_logging 3.1.8 → 4.0.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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/CHANGELOG.md +160 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/CONTRIBUTING.md +47 -0
- data/LICENSE.txt +21 -0
- data/README.md +191 -98
- data/SECURITY.md +16 -0
- data/lib/debug_logging/active_support_notifications.rb +4 -6
- data/lib/debug_logging/argument_printer.rb +105 -89
- data/lib/debug_logging/class_logger.rb +21 -19
- data/lib/debug_logging/class_notifier.rb +18 -22
- data/lib/debug_logging/configuration.rb +21 -23
- data/lib/debug_logging/constants.rb +3 -5
- data/lib/debug_logging/finalize.rb +1 -3
- data/lib/debug_logging/hooks.rb +22 -26
- data/lib/debug_logging/instance_logger.rb +23 -17
- data/lib/debug_logging/instance_logger_modulizer.rb +51 -47
- data/lib/debug_logging/instance_notifier.rb +18 -16
- data/lib/debug_logging/instance_notifier_modulizer.rb +37 -39
- data/lib/debug_logging/log_subscriber.rb +6 -7
- data/lib/debug_logging/util.rb +19 -13
- data/lib/debug_logging/version.rb +3 -3
- data/lib/debug_logging.rb +53 -37
- data/lib/simple_debug_logging.rb +4 -6
- data.tar.gz.sig +0 -0
- metadata +140 -57
- metadata.gz.sig +1 -0
- data/.coveralls.yml +0 -1
- data/.gitignore +0 -13
- data/.rspec +0 -2
- data/.rubocop.yml +0 -107
- data/.rubocop_todo.yml +0 -167
- data/.travis.yml +0 -36
- data/Gemfile +0 -12
- data/Rakefile +0 -8
- data/bin/console +0 -15
- data/bin/setup +0 -8
- data/debug_logging.gemspec +0 -42
data/lib/debug_logging/hooks.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "debug_logging/errors"
|
2
|
+
require "timeout"
|
3
3
|
|
4
4
|
module DebugLogging
|
5
5
|
module Hooks
|
@@ -16,16 +16,14 @@ module DebugLogging
|
|
16
16
|
names.each do |name|
|
17
17
|
meth = instance_method(name)
|
18
18
|
define_method(name) do |*args, &block|
|
19
|
-
|
20
|
-
|
21
|
-
meth.bind(self).call(*args, &block)
|
22
|
-
end
|
23
|
-
rescue Timeout::Error
|
24
|
-
error_args = [TimeoutError, 'execution expired', caller]
|
25
|
-
raise(*error_args) unless blk
|
26
|
-
|
27
|
-
instance_exec(*error_args, &blk)
|
19
|
+
Timeout.timeout(time) do
|
20
|
+
meth.bind_call(self, *args, &block)
|
28
21
|
end
|
22
|
+
rescue Timeout::Error
|
23
|
+
error_args = [TimeoutError, "execution expired", caller]
|
24
|
+
raise(*error_args) unless blk
|
25
|
+
|
26
|
+
instance_exec(*error_args, &blk)
|
29
27
|
end
|
30
28
|
end
|
31
29
|
end
|
@@ -33,17 +31,15 @@ module DebugLogging
|
|
33
31
|
def debug_rescue_on_fail(*names, &blk)
|
34
32
|
unless blk
|
35
33
|
raise NoBlockGiven,
|
36
|
-
|
37
|
-
|
34
|
+
".rescue_on_fail must be called with a block",
|
35
|
+
caller
|
38
36
|
end
|
39
37
|
names.each do |name|
|
40
38
|
meth = instance_method(name)
|
41
39
|
define_method(name) do |*args, &block|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
instance_exec(e, &blk)
|
46
|
-
end
|
40
|
+
meth.bind_call(self, *args, &block)
|
41
|
+
rescue StandardError => e
|
42
|
+
instance_exec(e, &blk)
|
47
43
|
end
|
48
44
|
end
|
49
45
|
end
|
@@ -51,14 +47,14 @@ module DebugLogging
|
|
51
47
|
def debug_before(*names, &blk)
|
52
48
|
unless blk
|
53
49
|
raise NoBlockGiven,
|
54
|
-
|
55
|
-
|
50
|
+
".before must be called with a block",
|
51
|
+
caller
|
56
52
|
end
|
57
53
|
names.each do |name|
|
58
54
|
meth = instance_method(name)
|
59
|
-
define_method
|
55
|
+
define_method(name) do |*args, &block|
|
60
56
|
instance_exec(name, *args, block, &blk)
|
61
|
-
meth.
|
57
|
+
meth.bind_call(self, *args, &block)
|
62
58
|
end
|
63
59
|
end
|
64
60
|
end
|
@@ -66,13 +62,13 @@ module DebugLogging
|
|
66
62
|
def debug_after(*names, &blk)
|
67
63
|
unless blk
|
68
64
|
raise NoBlockGiven,
|
69
|
-
|
70
|
-
|
65
|
+
".after must be called with a block",
|
66
|
+
caller
|
71
67
|
end
|
72
68
|
names.each do |name|
|
73
69
|
meth = instance_method(name)
|
74
|
-
define_method
|
75
|
-
result = meth.
|
70
|
+
define_method(name) do |*args, &block|
|
71
|
+
result = meth.bind_call(self, *args, &block)
|
76
72
|
instance_exec(result, &blk)
|
77
73
|
end
|
78
74
|
end
|
@@ -1,22 +1,28 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
module DebugLogging
|
4
|
-
|
5
|
-
def
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
2
|
+
module InstanceLogger
|
3
|
+
def i_logged(*methods_to_log)
|
4
|
+
methods_to_log, payload, config_opts = DebugLogging::Util.extract_payload_and_config(
|
5
|
+
method_names: methods_to_log,
|
6
|
+
payload: nil,
|
7
|
+
config: nil,
|
8
|
+
)
|
9
|
+
instance_method_modules =
|
10
|
+
Array(methods_to_log).map do |method_to_log|
|
11
|
+
DebugLogging::InstanceLoggerModulizer.to_mod(
|
12
|
+
methods_to_log: Array(method_to_log),
|
13
|
+
payload: payload,
|
14
|
+
config: config_opts,
|
15
|
+
)
|
16
|
+
end
|
17
|
+
wrapped_in_logs = Module.new do
|
18
|
+
singleton_class.send(:define_method, :included) do |host_class|
|
19
|
+
instance_method_modules.each do |mod|
|
20
|
+
host_class.prepend(mod)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
14
24
|
|
15
|
-
|
16
|
-
instance_method_logger = DebugLogging::InstanceLoggerModulizer.to_mod(methods_to_log: @instance_methods_to_log,
|
17
|
-
payload: @payload,
|
18
|
-
config: @config)
|
19
|
-
base.send(:prepend, instance_method_logger)
|
25
|
+
send(:include, wrapped_in_logs)
|
20
26
|
end
|
21
27
|
end
|
22
28
|
end
|
@@ -1,61 +1,65 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
module DebugLogging
|
4
2
|
module InstanceLoggerModulizer
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
Array(methods_to_log).each do |method_to_log|
|
13
|
-
method_to_log, method_payload, method_config_opts = DebugLogging::Util.extract_payload_and_config(
|
14
|
-
method_names: method_to_log,
|
15
|
-
payload: payload,
|
16
|
-
config: config_opts
|
3
|
+
class << self
|
4
|
+
def to_mod(methods_to_log: nil, payload: nil, config: nil)
|
5
|
+
Module.new do
|
6
|
+
methods_to_log, payload, config_opts = DebugLogging::Util.extract_payload_and_config(
|
7
|
+
method_names: Array(methods_to_log),
|
8
|
+
payload:,
|
9
|
+
config:,
|
17
10
|
)
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
method_name: method_to_log,
|
24
|
-
proxy_ref: 'ilm'
|
11
|
+
Array(methods_to_log).each do |method_to_log|
|
12
|
+
method_to_log, method_payload, method_config_opts = DebugLogging::Util.extract_payload_and_config(
|
13
|
+
method_names: method_to_log,
|
14
|
+
payload:,
|
15
|
+
config: config_opts,
|
25
16
|
)
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
17
|
+
define_method(method_to_log) do |*args, **kwargs, &block|
|
18
|
+
method_return_value = nil
|
19
|
+
config_proxy = DebugLogging::Util.config_proxy_finder(
|
20
|
+
scope: self.class,
|
21
|
+
config_opts: method_config_opts,
|
22
|
+
method_name: method_to_log,
|
23
|
+
proxy_ref: "ilm",
|
24
|
+
)
|
25
|
+
log_prefix = self.class.debug_invocation_to_s(
|
26
|
+
klass: self.class.to_s,
|
27
|
+
separator: "#",
|
28
|
+
method_to_log: method_to_log,
|
29
|
+
config_proxy: config_proxy,
|
30
|
+
)
|
31
|
+
invocation_id = self.class.debug_invocation_id_to_s(args:, kwargs:, config_proxy:)
|
39
32
|
config_proxy.log do
|
40
|
-
|
33
|
+
paydirt = DebugLogging::Util.payload_instance_variable_hydration(scope: self, payload: method_payload)
|
34
|
+
signature = self.class.debug_signature_to_s(args:, kwargs:, config_proxy:)
|
35
|
+
paymud = debug_payload_to_s(payload: paydirt, config_proxy:)
|
36
|
+
"#{log_prefix}#{signature}#{invocation_id} debug: #{paymud}"
|
41
37
|
end
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
rescue => error
|
46
|
-
if config_proxy.error_handler_proc
|
47
|
-
config_proxy.error_handler_proc.call(config_proxy, error, self, method_to_log, args)
|
48
|
-
else
|
49
|
-
raise error
|
38
|
+
if config_proxy.benchmarkable_for?(:debug_instance_benchmarks)
|
39
|
+
tms = Benchmark.measure do
|
40
|
+
method_return_value = super(*args, **kwargs, &block)
|
50
41
|
end
|
51
|
-
end
|
52
|
-
if config_proxy.exit_scope_markable? && invocation_id && !invocation_id.empty?
|
53
42
|
config_proxy.log do
|
54
|
-
"#{log_prefix}
|
43
|
+
"#{log_prefix} #{self.class.debug_benchmark_to_s(tms: tms)}#{invocation_id}"
|
44
|
+
end
|
45
|
+
else
|
46
|
+
begin
|
47
|
+
method_return_value = super(*args, **kwargs, &block)
|
48
|
+
rescue StandardError => e
|
49
|
+
if config_proxy.error_handler_proc
|
50
|
+
config_proxy.error_handler_proc.call(config_proxy, e, self, method_to_log, args, kwargs)
|
51
|
+
else
|
52
|
+
raise e
|
53
|
+
end
|
54
|
+
end
|
55
|
+
if config_proxy.exit_scope_markable? && invocation_id && !invocation_id.empty?
|
56
|
+
config_proxy.log do
|
57
|
+
"#{log_prefix} completed#{invocation_id}"
|
58
|
+
end
|
55
59
|
end
|
56
60
|
end
|
61
|
+
method_return_value
|
57
62
|
end
|
58
|
-
method_return_value
|
59
63
|
end
|
60
64
|
end
|
61
65
|
end
|
@@ -1,22 +1,24 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
module DebugLogging
|
4
|
-
|
5
|
-
def
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
2
|
+
module InstanceNotifier
|
3
|
+
def i_notified(*methods_to_log)
|
4
|
+
method_names, payload, config_opts = DebugLogging::Util.extract_payload_and_config(
|
5
|
+
method_names: methods_to_log,
|
6
|
+
payload: nil,
|
7
|
+
config: nil,
|
8
|
+
)
|
9
|
+
instance_method_notifier = DebugLogging::InstanceNotifierModulizer.to_mod(
|
10
|
+
methods_to_notify: Array(method_names),
|
11
|
+
payload: payload,
|
12
|
+
config: config_opts,
|
13
|
+
)
|
11
14
|
|
12
|
-
|
13
|
-
|
15
|
+
wrapped_in_notifier = Module.new do
|
16
|
+
singleton_class.send(:define_method, :included) do |host_class|
|
17
|
+
host_class.prepend(instance_method_notifier)
|
18
|
+
end
|
19
|
+
end
|
14
20
|
|
15
|
-
|
16
|
-
instance_method_notifier = DebugLogging::InstanceNotifierModulizer.to_mod(methods_to_notify: @instance_methods_to_notify,
|
17
|
-
payload: @payload,
|
18
|
-
config: @config)
|
19
|
-
base.send(:prepend, instance_method_notifier)
|
21
|
+
send(:include, wrapped_in_notifier)
|
20
22
|
end
|
21
23
|
end
|
22
24
|
end
|
@@ -1,49 +1,47 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
module DebugLogging
|
4
2
|
module InstanceNotifierModulizer
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
Array(methods_to_notify).each do |method_to_notify|
|
13
|
-
method_to_notify, method_payload, method_config_opts = DebugLogging::Util.extract_payload_and_config(
|
14
|
-
method_names: method_to_notify,
|
15
|
-
payload: payload,
|
16
|
-
config: config_opts
|
3
|
+
class << self
|
4
|
+
def to_mod(methods_to_notify: nil, payload: nil, config: nil)
|
5
|
+
Module.new do
|
6
|
+
methods_to_notify, payload, config_opts = DebugLogging::Util.extract_payload_and_config(
|
7
|
+
method_names: Array(methods_to_notify),
|
8
|
+
payload:,
|
9
|
+
config:,
|
17
10
|
)
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
) do |
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
11
|
+
Array(methods_to_notify).each do |method_to_notify|
|
12
|
+
method_to_notify, method_payload, method_config_opts = DebugLogging::Util.extract_payload_and_config(
|
13
|
+
method_names: method_to_notify,
|
14
|
+
payload:,
|
15
|
+
config: config_opts,
|
16
|
+
)
|
17
|
+
define_method(method_to_notify) do |*args, **kwargs, &block|
|
18
|
+
config_proxy = DebugLogging::Util.config_proxy_finder(
|
19
|
+
scope: self.class,
|
20
|
+
config_opts: method_config_opts,
|
21
|
+
method_name: method_to_notify,
|
22
|
+
proxy_ref: "inm",
|
23
|
+
) do |config_proxy|
|
24
|
+
ActiveSupport::Notifications.subscribe(
|
25
|
+
DebugLogging::ArgumentPrinter.debug_event_name_to_s(method_to_notify:),
|
26
|
+
) do |*subscribe_args|
|
27
|
+
config_proxy&.log do
|
28
|
+
DebugLogging::LogSubscriber.log_event(ActiveSupport::Notifications::Event.new(*subscribe_args))
|
29
|
+
end
|
30
30
|
end
|
31
31
|
end
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
super(*args, &block)
|
42
|
-
rescue => error
|
32
|
+
paydirt = DebugLogging::Util.payload_instance_variable_hydration(scope: self, payload: method_payload)
|
33
|
+
ActiveSupport::Notifications.instrument(
|
34
|
+
DebugLogging::ArgumentPrinter.debug_event_name_to_s(method_to_notify:),
|
35
|
+
debug_args: kwargs.empty? ? args : args + [kwargs],
|
36
|
+
config_proxy: config_proxy,
|
37
|
+
**paydirt,
|
38
|
+
) do
|
39
|
+
super(*args, **kwargs, &block)
|
40
|
+
rescue StandardError => e
|
43
41
|
if config_proxy.error_handler_proc
|
44
|
-
config_proxy.error_handler_proc.call(config_proxy,
|
42
|
+
config_proxy.error_handler_proc.call(config_proxy, e, self, method_to_notify, args, kwargs)
|
45
43
|
else
|
46
|
-
raise
|
44
|
+
raise e
|
47
45
|
end
|
48
46
|
end
|
49
47
|
end
|
@@ -1,6 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'active_support/log_subscriber'
|
1
|
+
require "active_support"
|
2
|
+
require "active_support/log_subscriber"
|
4
3
|
|
5
4
|
module DebugLogging
|
6
5
|
class LogSubscriber < ActiveSupport::LogSubscriber
|
@@ -12,7 +11,7 @@ module DebugLogging
|
|
12
11
|
end
|
13
12
|
attach_to :log
|
14
13
|
|
15
|
-
EVENT_FORMAT_STRING =
|
14
|
+
EVENT_FORMAT_STRING = "%<name>s (%<duration>.3f secs) start=%<time>s end=%<end>s args=%<args>s payload=%<payload>s"
|
16
15
|
|
17
16
|
def self.log_event(event)
|
18
17
|
@event = event
|
@@ -33,10 +32,10 @@ module DebugLogging
|
|
33
32
|
{
|
34
33
|
name: event.name,
|
35
34
|
duration: Rational(event.duration, 1000).to_f,
|
36
|
-
time: event.time,
|
37
|
-
end: event.end,
|
35
|
+
time: debug_time_to_s(event.time),
|
36
|
+
end: debug_time_to_s(event.end),
|
38
37
|
args: debug_signature_to_s(args: args, config_proxy: config_proxy),
|
39
|
-
payload: debug_payload_to_s(payload: payload, config_proxy: config_proxy)
|
38
|
+
payload: debug_payload_to_s(payload: payload, config_proxy: config_proxy),
|
40
39
|
}
|
41
40
|
end
|
42
41
|
end
|
data/lib/debug_logging/util.rb
CHANGED
@@ -9,11 +9,12 @@ module DebugLogging
|
|
9
9
|
# When scoped config is not present it will reuse the class' configuration object
|
10
10
|
scoped_payload = (method_names.is_a?(Array) && method_names.last.is_a?(Hash) && method_names.pop.clone(freeze: false)) || {}
|
11
11
|
payload = if payload
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
payload.merge(scoped_payload)
|
13
|
+
else
|
14
|
+
scoped_payload
|
15
|
+
end
|
16
16
|
config_opts = config&.clone(freeze: false) || {}
|
17
|
+
# puts "[EPAC] config: #{config}, scoped_payload: #{scoped_payload}, payload: #{payload}, config_opts: #{config_opts}"
|
17
18
|
unless payload.empty?
|
18
19
|
DebugLogging::Configuration::CONFIG_KEYS.each { |k| config_opts[k] = payload.delete(k) if payload.key?(k) }
|
19
20
|
end
|
@@ -39,7 +40,7 @@ module DebugLogging
|
|
39
40
|
[method_names, payload, config_opts]
|
40
41
|
end
|
41
42
|
|
42
|
-
def
|
43
|
+
def payload_instance_variable_hydration(scope:, payload:)
|
43
44
|
paydirt = {}
|
44
45
|
# TODO: Could make instance variable introspection configurable before or after method execution
|
45
46
|
if payload.key?(:instance_variables)
|
@@ -54,19 +55,24 @@ module DebugLogging
|
|
54
55
|
end
|
55
56
|
|
56
57
|
def config_proxy_finder(scope:, method_name:, proxy_ref:, config_opts: {}, &block)
|
57
|
-
if (proxy = scope.send(:instance_variable_get, DebugLogging::Configuration.config_pointer(
|
58
|
-
|
58
|
+
if (proxy = scope.send(:instance_variable_get, DebugLogging::Configuration.config_pointer(
|
59
|
+
proxy_ref,
|
60
|
+
method_name,
|
61
|
+
)))
|
59
62
|
proxy
|
60
63
|
else
|
61
64
|
base = scope.respond_to?(:debug_config) ? scope.debug_config : DebugLogging.debug_logging_configuration
|
62
65
|
proxy = if config_opts.empty?
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
66
|
+
base
|
67
|
+
else
|
68
|
+
DebugLogging::Configuration.new(**base.to_hash.merge(config_opts))
|
69
|
+
end
|
67
70
|
proxy.register(method_name)
|
68
|
-
scope.send(
|
69
|
-
|
71
|
+
scope.send(
|
72
|
+
:instance_variable_set,
|
73
|
+
DebugLogging::Configuration.config_pointer(proxy_ref, method_name),
|
74
|
+
proxy,
|
75
|
+
)
|
70
76
|
yield proxy if block
|
71
77
|
proxy
|
72
78
|
end
|
data/lib/debug_logging.rb
CHANGED
@@ -1,20 +1,23 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
require
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
require
|
8
|
-
|
9
|
-
|
10
|
-
require
|
11
|
-
require
|
12
|
-
require
|
13
|
-
require
|
14
|
-
require
|
15
|
-
require
|
16
|
-
require
|
17
|
-
require
|
1
|
+
# Std Lib
|
2
|
+
require "logger"
|
3
|
+
require "digest"
|
4
|
+
|
5
|
+
# External gems
|
6
|
+
require "version_gem"
|
7
|
+
require "colorized_string"
|
8
|
+
|
9
|
+
# This gem
|
10
|
+
require "debug_logging/constants"
|
11
|
+
require "debug_logging/version"
|
12
|
+
require "debug_logging/errors"
|
13
|
+
require "debug_logging/configuration"
|
14
|
+
require "debug_logging/util"
|
15
|
+
require "debug_logging/finalize"
|
16
|
+
require "debug_logging/argument_printer"
|
17
|
+
require "debug_logging/hooks"
|
18
|
+
require "debug_logging/instance_logger_modulizer"
|
19
|
+
require "debug_logging/instance_logger"
|
20
|
+
require "debug_logging/class_logger"
|
18
21
|
|
19
22
|
####################
|
20
23
|
# #
|
@@ -39,7 +42,8 @@ require 'debug_logging/class_logger'
|
|
39
42
|
#
|
40
43
|
# # For instance methods:
|
41
44
|
# # Option 1: specify the exact method(s) to add logging to
|
42
|
-
#
|
45
|
+
# extend DebugLogging::InstanceLogger
|
46
|
+
# i_logged [:drive, :stop]
|
43
47
|
#
|
44
48
|
# # Provides the `logged` method decorator
|
45
49
|
# extend DebugLogging::ClassLogger
|
@@ -54,7 +58,8 @@ require 'debug_logging/class_logger'
|
|
54
58
|
#
|
55
59
|
# # For instance methods:
|
56
60
|
# # Option 2: add logging to all instance methods defined above (but *not* defined below)
|
57
|
-
#
|
61
|
+
# extend DebugLogging::InstanceLogger
|
62
|
+
# i_logged instance_methods(false)
|
58
63
|
#
|
59
64
|
# def will_not_be_logged; false; end
|
60
65
|
#
|
@@ -63,29 +68,36 @@ require 'debug_logging/class_logger'
|
|
63
68
|
####################
|
64
69
|
|
65
70
|
module DebugLogging
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
base
|
72
|
-
|
73
|
-
|
71
|
+
# We can't compare with nil to check for no arguments passed as a configuration value,
|
72
|
+
# because nil can be an argument passed, hence:
|
73
|
+
ACTUAL_NOTHING = Object.new
|
74
|
+
|
75
|
+
class << self
|
76
|
+
def extended(base)
|
77
|
+
base.send(:extend, ArgumentPrinter)
|
78
|
+
base.send(:include, ArgumentPrinter)
|
79
|
+
base.send(:extend, ApiClassMethods)
|
80
|
+
base.send(:extend, ConfigClassMethods)
|
81
|
+
base.debug_config_reset(Configuration.new(**debug_logging_configuration.to_hash))
|
82
|
+
base.class_eval do
|
83
|
+
def base.inherited(subclass)
|
84
|
+
subclass.debug_config_reset(Configuration.new(**debug_config.to_hash))
|
85
|
+
end
|
74
86
|
end
|
75
87
|
end
|
76
|
-
end
|
77
88
|
|
78
|
-
|
89
|
+
#### API ####
|
79
90
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
91
|
+
# For single statement global config in an initializer
|
92
|
+
# e.g. DebugLogging.configuration.ellipsis = "..."
|
93
|
+
def configuration
|
94
|
+
self.debug_logging_configuration ||= Configuration.new
|
95
|
+
end
|
85
96
|
|
86
|
-
|
87
|
-
|
88
|
-
|
97
|
+
# For global config in an initializer with a block
|
98
|
+
def configure
|
99
|
+
yield(configuration)
|
100
|
+
end
|
89
101
|
end
|
90
102
|
|
91
103
|
module ApiClassMethods
|
@@ -272,3 +284,7 @@ module DebugLogging
|
|
272
284
|
|
273
285
|
self.debug_logging_configuration = Configuration.new # setup defaults
|
274
286
|
end
|
287
|
+
|
288
|
+
DebugLogging::Version.class_eval do
|
289
|
+
extend VersionGem::Basic
|
290
|
+
end
|
data/lib/simple_debug_logging.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
# Simpler version of what the sibling DebugLogging library does. Included as a bauble.
|
4
2
|
#
|
5
3
|
############# THIS IS A BAUBLE
|
@@ -35,7 +33,7 @@
|
|
35
33
|
# NOTE: The instance method manner of logging works on Ruby 2.0+
|
36
34
|
# NOTE: The class method manner of logging works on Ruby 2.1+
|
37
35
|
|
38
|
-
require
|
36
|
+
require "benchmark"
|
39
37
|
|
40
38
|
class SimpleDebugLogging < Module
|
41
39
|
def initialize(i_methods: nil)
|
@@ -57,11 +55,11 @@ class SimpleDebugLogging < Module
|
|
57
55
|
define_method(method_to_log.to_sym) do |*args|
|
58
56
|
method_return_value = nil
|
59
57
|
invocation_id = " ~#{args.object_id}@#{Time.now.to_i}~" if args
|
60
|
-
puts "#{self}
|
58
|
+
puts "#{self}::#{method_to_log}(#{args.map(&:inspect).join(", ")})#{invocation_id}"
|
61
59
|
elapsed = Benchmark.realtime do
|
62
60
|
method_return_value = original_method.call(*args)
|
63
61
|
end
|
64
|
-
puts "#{self}
|
62
|
+
puts "#{self}::#{method_to_log} ~#{args.hash}~ complete in #{elapsed}s#{invocation_id}"
|
65
63
|
method_return_value
|
66
64
|
end
|
67
65
|
end
|
@@ -76,7 +74,7 @@ class SimpleDebugLogging < Module
|
|
76
74
|
define_method(method_to_log.to_sym) do |*args, &block|
|
77
75
|
method_return_value = nil
|
78
76
|
invocation_id = " ~#{args.object_id}@#{Time.now.to_i}~" if args
|
79
|
-
puts "#{self.class}##{method_to_log}(#{args.map(&:inspect).join(
|
77
|
+
puts "#{self.class}##{method_to_log}(#{args.map(&:inspect).join(", ")})#{invocation_id}"
|
80
78
|
elapsed = Benchmark.realtime do
|
81
79
|
method_return_value = super(*args, &block)
|
82
80
|
end
|
data.tar.gz.sig
ADDED
Binary file
|