debug_logging 4.0.1 → 4.0.3
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 +237 -69
- data/CITATION.cff +20 -0
- data/CODE_OF_CONDUCT.md +79 -29
- data/CONTRIBUTING.md +242 -33
- data/FUNDING.md +74 -0
- data/LICENSE.md +12 -0
- data/README.md +491 -198
- data/RUBOCOP.md +71 -0
- data/SECURITY.md +15 -10
- data/certs/pboling.pem +27 -0
- data/lib/debug_logging/argument_printer.rb +34 -13
- data/lib/debug_logging/class_logger.rb +26 -56
- data/lib/debug_logging/class_notifier.rb +22 -38
- data/lib/debug_logging/colorized_string.rb +130 -0
- data/lib/debug_logging/configuration.rb +3 -2
- data/lib/debug_logging/finalize.rb +10 -8
- data/lib/debug_logging/hooks.rb +7 -5
- data/lib/debug_logging/instance_logger.rb +8 -2
- data/lib/debug_logging/instance_logger_modulizer.rb +19 -49
- data/lib/debug_logging/instance_notifier.rb +6 -0
- data/lib/debug_logging/instance_notifier_modulizer.rb +15 -31
- data/lib/debug_logging/lamb_dart/base.rb +46 -0
- data/lib/debug_logging/lamb_dart/log.rb +47 -0
- data/lib/debug_logging/lamb_dart/note.rb +30 -0
- data/lib/debug_logging/lamb_dart.rb +9 -0
- data/lib/debug_logging/lamb_dartable.rb +41 -0
- data/lib/debug_logging/lamb_darts/benchmarked.rb +19 -0
- data/lib/debug_logging/lamb_darts/enter_log.rb +16 -0
- data/lib/debug_logging/lamb_darts/error_handle.rb +28 -0
- data/lib/debug_logging/lamb_darts/exit_log.rb +15 -0
- data/lib/debug_logging/lamb_darts/notify.rb +17 -0
- data/lib/debug_logging/log_subscriber.rb +33 -26
- data/lib/debug_logging/util.rb +23 -19
- data/lib/debug_logging/version.rb +4 -1
- data/lib/debug_logging.rb +14 -9
- data/lib/simple_debug_logging.rb +18 -16
- data/sig/debug_logging/version.rbs +6 -0
- data.tar.gz.sig +0 -0
- metadata +129 -141
- metadata.gz.sig +0 -0
- data/LICENSE.txt +0 -21
|
@@ -8,61 +8,31 @@ module DebugLogging
|
|
|
8
8
|
payload:,
|
|
9
9
|
config:,
|
|
10
10
|
)
|
|
11
|
-
Array(methods_to_log).each do |
|
|
12
|
-
|
|
13
|
-
method_names:
|
|
11
|
+
Array(methods_to_log).each do |decorated_method|
|
|
12
|
+
decorated_method, method_payload, method_config_opts = DebugLogging::Util.extract_payload_and_config(
|
|
13
|
+
method_names: decorated_method,
|
|
14
14
|
payload:,
|
|
15
15
|
config: config_opts,
|
|
16
16
|
)
|
|
17
|
-
define_method(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
17
|
+
define_method(decorated_method) do |*args, **kwargs, &block|
|
|
18
|
+
lamb_dart = LambDart::Log.new(
|
|
19
|
+
instance: self,
|
|
20
|
+
method_config_opts:,
|
|
21
|
+
method_payload:,
|
|
22
|
+
args:,
|
|
23
|
+
kwargs:,
|
|
24
|
+
decorated_method:,
|
|
24
25
|
)
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
invocation_id = self.class.debug_invocation_id_to_s(args:, kwargs:, start_at:, config_proxy:)
|
|
34
|
-
config_proxy.log do
|
|
35
|
-
paydirt = DebugLogging::Util.payload_instance_variable_hydration(scope: self, payload: method_payload)
|
|
36
|
-
signature = self.class.debug_signature_to_s(args:, kwargs:, config_proxy:)
|
|
37
|
-
paymud = debug_payload_to_s(payload: paydirt, config_proxy:)
|
|
38
|
-
"#{start_timestamp}#{log_prefix}#{signature}#{invocation_id} debug: #{paymud}"
|
|
39
|
-
end
|
|
40
|
-
if config_proxy.benchmarkable_for?(:debug_instance_benchmarks)
|
|
41
|
-
tms = Benchmark.measure do
|
|
42
|
-
method_return_value = super(*args, **kwargs, &block)
|
|
43
|
-
end
|
|
44
|
-
end_timestamp = self.class.debug_time_to_s(Time.now, config_proxy:)
|
|
45
|
-
config_proxy.log do
|
|
46
|
-
"#{end_timestamp}#{log_prefix} #{self.class.debug_benchmark_to_s(tms: tms)}#{invocation_id}"
|
|
47
|
-
end
|
|
48
|
-
else
|
|
49
|
-
begin
|
|
50
|
-
method_return_value = super(*args, **kwargs, &block)
|
|
51
|
-
rescue StandardError => e
|
|
52
|
-
if config_proxy.error_handler_proc
|
|
53
|
-
config_proxy.error_handler_proc.call(config_proxy, e, self, method_to_log, args, kwargs)
|
|
54
|
-
else
|
|
55
|
-
raise e
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
if config_proxy.exit_scope_markable? && invocation_id && !invocation_id.empty?
|
|
59
|
-
end_timestamp = self.class.debug_time_to_s(Time.now, config_proxy:)
|
|
60
|
-
config_proxy.log do
|
|
61
|
-
"#{end_timestamp}#{log_prefix} completed#{invocation_id}"
|
|
62
|
-
end
|
|
26
|
+
real_mccoy = ->() {
|
|
27
|
+
super(*args, **kwargs, &block)
|
|
28
|
+
}
|
|
29
|
+
_dl_ld_enter_log(lamb_dart) do
|
|
30
|
+
_dl_ld_error_handle(lamb_dart) do
|
|
31
|
+
return _dl_ld_benchmarked(lamb_dart) { real_mccoy.call } if lamb_dart.bench?
|
|
32
|
+
|
|
33
|
+
_dl_ld_exit_log(lamb_dart) { real_mccoy.call }
|
|
63
34
|
end
|
|
64
35
|
end
|
|
65
|
-
method_return_value
|
|
66
36
|
end
|
|
67
37
|
end
|
|
68
38
|
end
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
module DebugLogging
|
|
2
2
|
module InstanceNotifier
|
|
3
|
+
class << self
|
|
4
|
+
def extended(base)
|
|
5
|
+
base.include(LambDartable::Note)
|
|
6
|
+
end
|
|
7
|
+
end
|
|
8
|
+
|
|
3
9
|
def i_notified(*methods_to_log)
|
|
4
10
|
method_names, payload, config_opts = DebugLogging::Util.extract_payload_and_config(
|
|
5
11
|
method_names: methods_to_log,
|
|
@@ -8,40 +8,24 @@ module DebugLogging
|
|
|
8
8
|
payload:,
|
|
9
9
|
config:,
|
|
10
10
|
)
|
|
11
|
-
Array(methods_to_notify).each do |
|
|
12
|
-
|
|
13
|
-
method_names:
|
|
11
|
+
Array(methods_to_notify).each do |decorated_method|
|
|
12
|
+
decorated_method, method_payload, method_config_opts = DebugLogging::Util.extract_payload_and_config(
|
|
13
|
+
method_names: decorated_method,
|
|
14
14
|
payload:,
|
|
15
15
|
config: config_opts,
|
|
16
16
|
)
|
|
17
|
-
define_method(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
end
|
|
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
|
|
41
|
-
if config_proxy.error_handler_proc
|
|
42
|
-
config_proxy.error_handler_proc.call(config_proxy, e, self, method_to_notify, args, kwargs)
|
|
43
|
-
else
|
|
44
|
-
raise e
|
|
17
|
+
define_method(decorated_method) do |*args, **kwargs, &block|
|
|
18
|
+
lamb_dart = LambDart::Note.new(
|
|
19
|
+
instance: self,
|
|
20
|
+
method_config_opts:,
|
|
21
|
+
method_payload:,
|
|
22
|
+
args:,
|
|
23
|
+
kwargs:,
|
|
24
|
+
decorated_method:,
|
|
25
|
+
)
|
|
26
|
+
_dl_ld_notify(lamb_dart) do
|
|
27
|
+
_dl_ld_error_handle(lamb_dart) do
|
|
28
|
+
super(*args, **kwargs, &block)
|
|
45
29
|
end
|
|
46
30
|
end
|
|
47
31
|
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
require "forwardable"
|
|
2
|
+
|
|
3
|
+
module DebugLogging
|
|
4
|
+
module LambDart
|
|
5
|
+
class Base
|
|
6
|
+
extend Forwardable
|
|
7
|
+
|
|
8
|
+
attr_reader :instance, # For ClassLogger, this will be the same as klass
|
|
9
|
+
:klass,
|
|
10
|
+
:is_class,
|
|
11
|
+
:config_proxy,
|
|
12
|
+
:method_payload,
|
|
13
|
+
:args,
|
|
14
|
+
:kwargs,
|
|
15
|
+
:scope_term,
|
|
16
|
+
:decorated_method
|
|
17
|
+
|
|
18
|
+
def_delegator :@config_proxy, :error_handler_proc
|
|
19
|
+
|
|
20
|
+
def initialize(instance: nil, klass: nil, method_config_opts:, method_payload:, args:, kwargs:, decorated_method:)
|
|
21
|
+
@instance = instance || klass
|
|
22
|
+
@klass = klass || instance.class
|
|
23
|
+
@method_payload = method_payload
|
|
24
|
+
@args = args
|
|
25
|
+
@kwargs = kwargs
|
|
26
|
+
@decorated_method = decorated_method
|
|
27
|
+
@is_class = (self.klass == self.instance)
|
|
28
|
+
@scope_term = is_class ? "class" : "instance"
|
|
29
|
+
@config_proxy = DebugLogging::Util.config_proxy_finder(
|
|
30
|
+
scope: self.klass,
|
|
31
|
+
config_opts: method_config_opts,
|
|
32
|
+
method_name: self.decorated_method,
|
|
33
|
+
proxy_ref:,
|
|
34
|
+
) do |proxy|
|
|
35
|
+
yield proxy if block_given?
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
private
|
|
40
|
+
|
|
41
|
+
def proxy_ref
|
|
42
|
+
raise "#{self.class}##{__method__} is not defined, please fix!"
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
module DebugLogging
|
|
2
|
+
module LambDart
|
|
3
|
+
class Log < Base
|
|
4
|
+
attr_reader :log_prefix,
|
|
5
|
+
:invocation_id,
|
|
6
|
+
:start_at
|
|
7
|
+
|
|
8
|
+
def initialize(...)
|
|
9
|
+
@start_at = Time.now
|
|
10
|
+
super
|
|
11
|
+
@log_prefix = klass.debug_invocation_to_s(
|
|
12
|
+
klass: klass.to_s,
|
|
13
|
+
separator: is_class ? "::" : "#",
|
|
14
|
+
decorated_method:,
|
|
15
|
+
config_proxy:,
|
|
16
|
+
)
|
|
17
|
+
@invocation_id = klass.debug_invocation_id_to_s(args:, config_proxy:)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def end_timestamp
|
|
21
|
+
klass.debug_time_to_s(Time.now, config_proxy:)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def benchmarked(tms)
|
|
25
|
+
klass.debug_benchmark_to_s(tms: tms)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def mark_exit_scope?
|
|
29
|
+
config_proxy.exit_scope_markable? && invocation_id && !invocation_id.empty?
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def bench_scope
|
|
33
|
+
"debug_#{scope_term}_benchmarks".to_sym
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def bench?
|
|
37
|
+
config_proxy.benchmarkable_for?(bench_scope)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
private
|
|
41
|
+
|
|
42
|
+
def proxy_ref
|
|
43
|
+
is_class ? "kl" : "ilm"
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
module DebugLogging
|
|
2
|
+
module LambDart
|
|
3
|
+
class Note < Base
|
|
4
|
+
attr_reader :debug_args
|
|
5
|
+
|
|
6
|
+
def initialize(...)
|
|
7
|
+
super do |proxy|
|
|
8
|
+
subscribe(proxy)
|
|
9
|
+
end
|
|
10
|
+
@debug_args = kwargs.empty? ? args : args + [kwargs]
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
private
|
|
14
|
+
|
|
15
|
+
def subscribe(proxy)
|
|
16
|
+
ActiveSupport::Notifications.subscribe(
|
|
17
|
+
DebugLogging::ArgumentPrinter.debug_event_name_to_s(decorated_method: decorated_method),
|
|
18
|
+
) do |*subscribe_args|
|
|
19
|
+
proxy.log do
|
|
20
|
+
DebugLogging::LogSubscriber.log_event(ActiveSupport::Notifications::Event.new(*subscribe_args))
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def proxy_ref
|
|
26
|
+
is_class ? "kn" : "inm"
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
require_relative "lamb_darts/benchmarked"
|
|
2
|
+
require_relative "lamb_darts/enter_log"
|
|
3
|
+
require_relative "lamb_darts/error_handle"
|
|
4
|
+
require_relative "lamb_darts/exit_log"
|
|
5
|
+
require_relative "lamb_darts/notify"
|
|
6
|
+
|
|
7
|
+
module DebugLogging
|
|
8
|
+
module LambDartable
|
|
9
|
+
module Log
|
|
10
|
+
class << self
|
|
11
|
+
def included(base)
|
|
12
|
+
base.include(LambDarts::Benchmarked)
|
|
13
|
+
base.include(LambDarts::EnterLog)
|
|
14
|
+
base.include(LambDarts::ErrorHandle)
|
|
15
|
+
base.include(LambDarts::ExitLog)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def extended(base)
|
|
19
|
+
base.extend(LambDarts::Benchmarked)
|
|
20
|
+
base.extend(LambDarts::EnterLog)
|
|
21
|
+
base.extend(LambDarts::ErrorHandle)
|
|
22
|
+
base.extend(LambDarts::ExitLog)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
module Note
|
|
28
|
+
class << self
|
|
29
|
+
def included(base)
|
|
30
|
+
base.include(LambDarts::ErrorHandle)
|
|
31
|
+
base.include(LambDarts::Notify)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def extended(base)
|
|
35
|
+
base.extend(LambDarts::ErrorHandle)
|
|
36
|
+
base.extend(LambDarts::Notify)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module DebugLogging
|
|
2
|
+
module LambDarts
|
|
3
|
+
module Benchmarked
|
|
4
|
+
def _dl_ld_benchmarked(ld)
|
|
5
|
+
brv = nil
|
|
6
|
+
# Benchmarking as close to the real mccoy as possible,
|
|
7
|
+
# so as to not pollute performance tracking with the effects of debug_logging,
|
|
8
|
+
# which may be removed once data has been gathered, or turned off.
|
|
9
|
+
tms = Benchmark.measure do
|
|
10
|
+
brv = yield
|
|
11
|
+
end
|
|
12
|
+
ld.config_proxy.log do
|
|
13
|
+
"#{ld.end_timestamp}#{ld.log_prefix} #{ld.benchmarked(tms)}#{ld.invocation_id}"
|
|
14
|
+
end
|
|
15
|
+
brv
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module DebugLogging
|
|
2
|
+
module LambDarts
|
|
3
|
+
module EnterLog
|
|
4
|
+
def _dl_ld_enter_log(ld)
|
|
5
|
+
start_timestamp = ld.klass.debug_time_to_s(ld.start_at, config_proxy: ld.config_proxy)
|
|
6
|
+
ld.config_proxy.log do
|
|
7
|
+
paydirt = DebugLogging::Util.payload_instance_variable_hydration(scope: ld.instance, payload: ld.method_payload)
|
|
8
|
+
signature = ld.klass.debug_signature_to_s(args: ld.args, kwargs: ld.kwargs, config_proxy: ld.config_proxy)
|
|
9
|
+
paymud = ld.instance.debug_payload_to_s(payload: paydirt, config_proxy: ld.config_proxy)
|
|
10
|
+
"#{start_timestamp}#{ld.log_prefix}#{signature}#{ld.invocation_id} debug: #{paymud}"
|
|
11
|
+
end
|
|
12
|
+
yield
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
module DebugLogging
|
|
2
|
+
module LambDarts
|
|
3
|
+
module ErrorHandle
|
|
4
|
+
def _dl_ld_error_handle(ld)
|
|
5
|
+
if ld.config_proxy.error_handler_proc
|
|
6
|
+
begin
|
|
7
|
+
yield
|
|
8
|
+
rescue StandardError => e
|
|
9
|
+
if ld.error_handler_proc
|
|
10
|
+
ld.error_handler_proc.call(
|
|
11
|
+
ld.config_proxy,
|
|
12
|
+
e,
|
|
13
|
+
self,
|
|
14
|
+
ld.decorated_method,
|
|
15
|
+
*ld.args,
|
|
16
|
+
**ld.kwargs,
|
|
17
|
+
)
|
|
18
|
+
else
|
|
19
|
+
raise e
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
else
|
|
23
|
+
yield
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module DebugLogging
|
|
2
|
+
module LambDarts
|
|
3
|
+
module ExitLog
|
|
4
|
+
def _dl_ld_exit_log(ld)
|
|
5
|
+
hrv = yield
|
|
6
|
+
return hrv unless ld.mark_exit_scope?
|
|
7
|
+
|
|
8
|
+
ld.config_proxy.log do
|
|
9
|
+
"#{ld.end_timestamp}#{ld.log_prefix} completed#{ld.invocation_id}"
|
|
10
|
+
end
|
|
11
|
+
hrv
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module DebugLogging
|
|
2
|
+
module LambDarts
|
|
3
|
+
module Notify
|
|
4
|
+
def _dl_ld_notify(ld)
|
|
5
|
+
paydirt = DebugLogging::Util.payload_instance_variable_hydration(scope: ld.instance, payload: ld.method_payload)
|
|
6
|
+
ActiveSupport::Notifications.instrument(
|
|
7
|
+
DebugLogging::ArgumentPrinter.debug_event_name_to_s(decorated_method: ld.decorated_method),
|
|
8
|
+
debug_args: ld.debug_args,
|
|
9
|
+
config_proxy: ld.config_proxy,
|
|
10
|
+
**paydirt,
|
|
11
|
+
) do
|
|
12
|
+
yield
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -7,36 +7,43 @@ module DebugLogging
|
|
|
7
7
|
extend DebugLogging::ArgumentPrinter
|
|
8
8
|
|
|
9
9
|
class << self
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
def event
|
|
11
|
+
@@event
|
|
12
|
+
end
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
def event=(value)
|
|
15
|
+
@@event = value
|
|
16
|
+
end
|
|
15
17
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
def log_event(event)
|
|
19
|
+
self.event = event
|
|
20
|
+
if event.payload && event.payload[:exception_object]
|
|
21
|
+
exception = event.payload[:exception_object]
|
|
22
|
+
"#{event.name} [ERROR] : \n#{exception.class} : #{exception.message}\n" + exception.backtrace.join("\n")
|
|
23
|
+
else
|
|
24
|
+
format(EVENT_FORMAT_STRING, event_to_format_options(event))
|
|
25
|
+
end
|
|
23
26
|
end
|
|
24
|
-
end
|
|
25
27
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
28
|
+
# @param [ActiveSupport::Notifications::Event]
|
|
29
|
+
# @return [Hash]
|
|
30
|
+
def event_to_format_options(event)
|
|
31
|
+
args = event.payload[:debug_args]
|
|
32
|
+
config_proxy = event.payload[:config_proxy]
|
|
33
|
+
payload = event.payload.reject { |k, _| EXCLUDE_FROM_PAYLOAD.include?(k) }
|
|
34
|
+
{
|
|
35
|
+
name: event.name,
|
|
36
|
+
duration: Rational(event.duration, 1000).to_f,
|
|
37
|
+
time: debug_event_time_to_s(event.time),
|
|
38
|
+
end: debug_event_time_to_s(event.end),
|
|
39
|
+
args: debug_signature_to_s(args: args, config_proxy: config_proxy),
|
|
40
|
+
payload: debug_payload_to_s(payload: payload, config_proxy: config_proxy),
|
|
41
|
+
}
|
|
42
|
+
end
|
|
40
43
|
end
|
|
44
|
+
|
|
45
|
+
attach_to :log
|
|
46
|
+
|
|
47
|
+
EVENT_FORMAT_STRING = "%<name>s (%<duration>.3f secs) start=%<time>s end=%<end>s args=%<args>s payload=%<payload>s"
|
|
41
48
|
end
|
|
42
49
|
end
|
data/lib/debug_logging/util.rb
CHANGED
|
@@ -71,27 +71,31 @@ module DebugLogging
|
|
|
71
71
|
end
|
|
72
72
|
|
|
73
73
|
def config_proxy_finder(scope:, method_name:, proxy_ref:, config_opts: {}, &block)
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
74
|
+
proxy = scope.send(
|
|
75
|
+
:instance_variable_get,
|
|
76
|
+
DebugLogging::Configuration.config_pointer(
|
|
77
|
+
proxy_ref,
|
|
78
|
+
method_name,
|
|
79
|
+
),
|
|
80
|
+
)
|
|
81
|
+
# short circuit on subsequent calls is required
|
|
82
|
+
# so we only register notifications once
|
|
83
|
+
return proxy if proxy
|
|
84
|
+
|
|
85
|
+
base = scope.respond_to?(:debug_config) ? scope.debug_config : DebugLogging.debug_logging_configuration
|
|
86
|
+
proxy = if config_opts.empty?
|
|
87
|
+
base
|
|
79
88
|
else
|
|
80
|
-
base
|
|
81
|
-
proxy = if config_opts.empty?
|
|
82
|
-
base
|
|
83
|
-
else
|
|
84
|
-
DebugLogging::Configuration.new(**base.to_hash.merge(config_opts))
|
|
85
|
-
end
|
|
86
|
-
proxy.register(method_name)
|
|
87
|
-
scope.send(
|
|
88
|
-
:instance_variable_set,
|
|
89
|
-
DebugLogging::Configuration.config_pointer(proxy_ref, method_name),
|
|
90
|
-
proxy,
|
|
91
|
-
)
|
|
92
|
-
yield proxy if block
|
|
93
|
-
proxy
|
|
89
|
+
DebugLogging::Configuration.new(**base.to_hash.merge(config_opts))
|
|
94
90
|
end
|
|
91
|
+
proxy.register(method_name)
|
|
92
|
+
scope.send(
|
|
93
|
+
:instance_variable_set,
|
|
94
|
+
DebugLogging::Configuration.config_pointer(proxy_ref, method_name),
|
|
95
|
+
proxy,
|
|
96
|
+
)
|
|
97
|
+
yield proxy if block
|
|
98
|
+
proxy
|
|
95
99
|
end
|
|
96
100
|
end
|
|
97
101
|
end
|
data/lib/debug_logging.rb
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
# Std Lib
|
|
2
4
|
require "logger"
|
|
3
5
|
require "digest"
|
|
4
6
|
|
|
5
7
|
# External gems
|
|
6
8
|
require "version_gem"
|
|
7
|
-
|
|
9
|
+
require_relative "debug_logging/version"
|
|
10
|
+
|
|
11
|
+
require "debug_logging/colorized_string"
|
|
8
12
|
|
|
9
13
|
# This gem
|
|
10
14
|
require "debug_logging/constants"
|
|
@@ -15,17 +19,12 @@ require "debug_logging/util"
|
|
|
15
19
|
require "debug_logging/finalize"
|
|
16
20
|
require "debug_logging/argument_printer"
|
|
17
21
|
require "debug_logging/hooks"
|
|
22
|
+
require "debug_logging/lamb_dart"
|
|
23
|
+
require "debug_logging/lamb_dartable"
|
|
18
24
|
require "debug_logging/instance_logger_modulizer"
|
|
19
25
|
require "debug_logging/instance_logger"
|
|
20
26
|
require "debug_logging/class_logger"
|
|
21
27
|
|
|
22
|
-
####################
|
|
23
|
-
# #
|
|
24
|
-
# NOTE: The manner this is made to work for class methods is totally different
|
|
25
|
-
# than the way this is made to work for instance methods.
|
|
26
|
-
# NOTE: The instance method manner works on Ruby 2.0+
|
|
27
|
-
# NOTE: The class method manner works on Ruby 2.1+
|
|
28
|
-
# #
|
|
29
28
|
####################
|
|
30
29
|
# #
|
|
31
30
|
# USAGE (see specs)#
|
|
@@ -121,7 +120,13 @@ module DebugLogging
|
|
|
121
120
|
|
|
122
121
|
#### CONFIG ####
|
|
123
122
|
class << self
|
|
124
|
-
|
|
123
|
+
def debug_logging_configuration
|
|
124
|
+
@@debug_logging_configuration
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def debug_logging_configuration=(config)
|
|
128
|
+
@@debug_logging_configuration = config
|
|
129
|
+
end
|
|
125
130
|
end
|
|
126
131
|
|
|
127
132
|
module ConfigClassMethods
|
data/lib/simple_debug_logging.rb
CHANGED
|
@@ -49,17 +49,17 @@ class SimpleDebugLogging < Module
|
|
|
49
49
|
|
|
50
50
|
module ClassMethodLogger
|
|
51
51
|
def logged(*methods_to_log)
|
|
52
|
-
methods_to_log.each do |
|
|
53
|
-
original_method = method(
|
|
52
|
+
methods_to_log.each do |decorated_method|
|
|
53
|
+
original_method = method(decorated_method)
|
|
54
54
|
(class << self; self; end).class_eval do
|
|
55
|
-
define_method(
|
|
55
|
+
define_method(decorated_method.to_sym) do |*args|
|
|
56
56
|
method_return_value = nil
|
|
57
57
|
invocation_id = " ~#{args.object_id}@#{Time.now.to_i}~" if args
|
|
58
|
-
puts "#{self}::#{
|
|
58
|
+
puts "#{self}::#{decorated_method}(#{args.map(&:inspect).join(", ")})#{invocation_id}"
|
|
59
59
|
elapsed = Benchmark.realtime do
|
|
60
60
|
method_return_value = original_method.call(*args)
|
|
61
61
|
end
|
|
62
|
-
puts "#{self}::#{
|
|
62
|
+
puts "#{self}::#{decorated_method} ~#{args.hash}~ complete in #{elapsed}s#{invocation_id}"
|
|
63
63
|
method_return_value
|
|
64
64
|
end
|
|
65
65
|
end
|
|
@@ -68,18 +68,20 @@ class SimpleDebugLogging < Module
|
|
|
68
68
|
end
|
|
69
69
|
|
|
70
70
|
module InstanceMethodLoggerModulizer
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
71
|
+
class << self
|
|
72
|
+
def to_mod(methods_to_log = [])
|
|
73
|
+
Module.new do
|
|
74
|
+
Array(methods_to_log).each do |decorated_method|
|
|
75
|
+
define_method(decorated_method.to_sym) do |*args, &block|
|
|
76
|
+
method_return_value = nil
|
|
77
|
+
invocation_id = " ~#{args.object_id}@#{Time.now.to_i}~" if args
|
|
78
|
+
puts "#{self.class}##{decorated_method}(#{args.map(&:inspect).join(", ")})#{invocation_id}"
|
|
79
|
+
elapsed = Benchmark.realtime do
|
|
80
|
+
method_return_value = super(*args, &block)
|
|
81
|
+
end
|
|
82
|
+
puts "#{self.class}##{decorated_method} ~#{args.hash}~ complete in #{elapsed}s#{invocation_id}"
|
|
83
|
+
method_return_value
|
|
80
84
|
end
|
|
81
|
-
puts "#{self.class}##{method_to_log} ~#{args.hash}~ complete in #{elapsed}s#{invocation_id}"
|
|
82
|
-
method_return_value
|
|
83
85
|
end
|
|
84
86
|
end
|
|
85
87
|
end
|