debug_logging 3.1.0 → 3.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +8 -0
- data/.rubocop_todo.yml +97 -63
- data/.travis.yml +2 -2
- data/README.md +147 -47
- data/debug_logging.gemspec +6 -3
- data/lib/debug_logging.rb +17 -0
- data/lib/debug_logging/argument_printer.rb +123 -27
- data/lib/debug_logging/class_logger.rb +32 -27
- data/lib/debug_logging/class_notifier.rb +37 -30
- data/lib/debug_logging/configuration.rb +53 -51
- data/lib/debug_logging/errors.rb +7 -0
- data/lib/debug_logging/finalize.rb +20 -0
- data/lib/debug_logging/hooks.rb +82 -0
- data/lib/debug_logging/instance_logger.rb +5 -2
- data/lib/debug_logging/instance_logger_modulizer.rb +23 -17
- data/lib/debug_logging/instance_notifier.rb +6 -2
- data/lib/debug_logging/instance_notifier_modulizer.rb +28 -32
- data/lib/debug_logging/log_subscriber.rb +11 -3
- data/lib/debug_logging/util.rb +75 -0
- data/lib/debug_logging/version.rb +1 -1
- data/lib/simple_debug_logging.rb +2 -0
- metadata +58 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 77770fe7ac99f46e73cbcbc12eeaef1ad69978ab9880ae8758758d203c9e1267
|
4
|
+
data.tar.gz: 9e09d725eba529f29103468581fb8718eee02946d02a97cbeb444a7df946bfc1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e26b9a71370c7f87ffc03a202cee289a0510f9e552dba96edd7034fad32f16c6d4b83da7b64d2f4e516d81af0743b3a70f21896f9e08bd87f68c962e8aeb12b9
|
7
|
+
data.tar.gz: e85efa9c27319c63fc3d9923602ac901eb1ca32ecbe726f0cdd54eec656706426b17a69d3ee2b1bb96f76b8b801569b7b54b544966903f9316603da54c3ff64f
|
data/.rubocop.yml
CHANGED
data/.rubocop_todo.yml
CHANGED
@@ -1,89 +1,134 @@
|
|
1
|
-
inherit_from: .rubocop.yml
|
2
|
-
|
3
1
|
# This configuration was generated by
|
4
2
|
# `rubocop --auto-gen-config`
|
5
|
-
# on 2020-10
|
3
|
+
# on 2020-12-10 04:35:55 UTC using RuboCop version 1.6.0.
|
6
4
|
# The point is for the user to remove these configuration records
|
7
5
|
# one by one as the offenses are removed from the code base.
|
8
6
|
# Note that changes in the inspected code, or installation of new
|
9
7
|
# versions of RuboCop, may require this file to be generated again.
|
10
8
|
|
11
|
-
# Offense count:
|
12
|
-
|
13
|
-
# Include: **/*.gemspec
|
14
|
-
Gemspec/RequiredRubyVersion:
|
9
|
+
# Offense count: 7
|
10
|
+
Lint/DuplicateMethods:
|
15
11
|
Exclude:
|
16
|
-
- '
|
17
|
-
|
18
|
-
# Offense count: 1
|
19
|
-
# Cop supports --auto-correct.
|
20
|
-
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters.
|
21
|
-
# SupportedStyles: space, no_space
|
22
|
-
# SupportedStylesForEmptyBraces: space, no_space
|
23
|
-
Layout/SpaceInsideBlockBraces:
|
24
|
-
Exclude:
|
25
|
-
- 'lib/debug_logging/argument_printer.rb'
|
12
|
+
- 'README.md'
|
26
13
|
|
27
|
-
# Offense count:
|
28
|
-
# Configuration parameters: IgnoredMethods.
|
14
|
+
# Offense count: 6
|
15
|
+
# Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
|
29
16
|
Metrics/AbcSize:
|
30
|
-
Max:
|
17
|
+
Max: 96
|
31
18
|
|
32
|
-
# Offense count:
|
33
|
-
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods.
|
34
|
-
#
|
19
|
+
# Offense count: 58
|
20
|
+
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
|
21
|
+
# IgnoredMethods: refine
|
35
22
|
Metrics/BlockLength:
|
36
|
-
Max:
|
23
|
+
Max: 851
|
37
24
|
|
38
25
|
# Offense count: 6
|
39
26
|
# Configuration parameters: CountBlocks.
|
40
27
|
Metrics/BlockNesting:
|
41
28
|
Max: 4
|
42
29
|
|
43
|
-
# Offense count: 1
|
44
|
-
# Configuration parameters: CountComments, CountAsOne.
|
45
|
-
Metrics/ClassLength:
|
46
|
-
Max: 101
|
47
|
-
|
48
30
|
# Offense count: 4
|
49
31
|
# Configuration parameters: IgnoredMethods.
|
50
32
|
Metrics/CyclomaticComplexity:
|
51
|
-
Max:
|
33
|
+
Max: 24
|
52
34
|
|
53
|
-
# Offense count:
|
54
|
-
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods.
|
35
|
+
# Offense count: 15
|
36
|
+
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
|
55
37
|
Metrics/MethodLength:
|
56
|
-
Max:
|
38
|
+
Max: 75
|
57
39
|
|
58
|
-
# Offense count:
|
40
|
+
# Offense count: 2
|
59
41
|
# Configuration parameters: CountComments, CountAsOne.
|
60
42
|
Metrics/ModuleLength:
|
61
43
|
Max: 112
|
62
44
|
|
63
|
-
# Offense count:
|
45
|
+
# Offense count: 5
|
64
46
|
# Configuration parameters: IgnoredMethods.
|
65
47
|
Metrics/PerceivedComplexity:
|
66
|
-
Max:
|
48
|
+
Max: 31
|
67
49
|
|
68
|
-
# Offense count:
|
69
|
-
# Configuration parameters:
|
70
|
-
|
50
|
+
# Offense count: 3
|
51
|
+
# Configuration parameters: EnforcedStyleForLeadingUnderscores.
|
52
|
+
# SupportedStylesForLeadingUnderscores: disallowed, required, optional
|
53
|
+
Naming/MemoizedInstanceVariableName:
|
71
54
|
Exclude:
|
72
55
|
- 'lib/debug_logging/configuration.rb'
|
73
56
|
|
57
|
+
# Offense count: 60
|
58
|
+
# Configuration parameters: Prefixes.
|
59
|
+
# Prefixes: when, with, without
|
60
|
+
RSpec/ContextWording:
|
61
|
+
Exclude:
|
62
|
+
- 'spec/debug_logging/class_logger_spec.rb'
|
63
|
+
- 'spec/debug_logging/class_notifier_spec.rb'
|
64
|
+
- 'spec/debug_logging/configuration_spec.rb'
|
65
|
+
- 'spec/debug_logging/instance_logger_spec.rb'
|
66
|
+
- 'spec/debug_logging/instance_notifier_spec.rb'
|
67
|
+
- 'spec/debug_logging_spec.rb'
|
68
|
+
|
69
|
+
# Offense count: 46
|
70
|
+
# Configuration parameters: Max.
|
71
|
+
RSpec/ExampleLength:
|
72
|
+
Exclude:
|
73
|
+
- 'spec/debug_logging/class_logger_spec.rb'
|
74
|
+
- 'spec/debug_logging/class_notifier_spec.rb'
|
75
|
+
- 'spec/debug_logging/configuration_spec.rb'
|
76
|
+
- 'spec/debug_logging/instance_logger_spec.rb'
|
77
|
+
- 'spec/debug_logging/instance_notifier_spec.rb'
|
78
|
+
- 'spec/debug_logging/log_subscriber_spec.rb'
|
79
|
+
- 'spec/debug_logging_spec.rb'
|
80
|
+
|
81
|
+
# Offense count: 53
|
82
|
+
# Configuration parameters: AssignmentOnly.
|
83
|
+
RSpec/InstanceVariable:
|
84
|
+
Exclude:
|
85
|
+
- 'spec/debug_logging/class_notifier_spec.rb'
|
86
|
+
- 'spec/debug_logging/instance_notifier_spec.rb'
|
87
|
+
- 'spec/debug_logging/log_subscriber_spec.rb'
|
88
|
+
|
89
|
+
# Offense count: 4
|
90
|
+
RSpec/LeakyConstantDeclaration:
|
91
|
+
Exclude:
|
92
|
+
- 'spec/debug_logging/configuration_spec.rb'
|
93
|
+
|
94
|
+
# Offense count: 23
|
95
|
+
# Configuration parameters: .
|
96
|
+
# SupportedStyles: have_received, receive
|
97
|
+
RSpec/MessageSpies:
|
98
|
+
EnforcedStyle: receive
|
99
|
+
|
100
|
+
# Offense count: 80
|
101
|
+
RSpec/MultipleExpectations:
|
102
|
+
Max: 32
|
103
|
+
|
74
104
|
# Offense count: 1
|
75
|
-
#
|
76
|
-
|
77
|
-
|
78
|
-
|
105
|
+
# Configuration parameters: AllowSubject.
|
106
|
+
RSpec/MultipleMemoizedHelpers:
|
107
|
+
Max: 10
|
108
|
+
|
109
|
+
# Offense count: 27
|
110
|
+
RSpec/NestedGroups:
|
111
|
+
Max: 5
|
112
|
+
|
113
|
+
# Offense count: 1
|
114
|
+
# Configuration parameters: IgnoreNameless, IgnoreSymbolicNames.
|
115
|
+
RSpec/VerifiedDoubles:
|
79
116
|
Exclude:
|
80
|
-
- '
|
117
|
+
- 'spec/support/shared_context.rb'
|
118
|
+
|
119
|
+
# Offense count: 1
|
120
|
+
# Configuration parameters: AllowedChars.
|
121
|
+
Style/AsciiComments:
|
122
|
+
Exclude:
|
123
|
+
- '**/*.md'
|
124
|
+
- '**/*.markdown'
|
125
|
+
- 'lib/debug_logging/configuration.rb'
|
81
126
|
|
82
|
-
# Offense count:
|
127
|
+
# Offense count: 13
|
83
128
|
Style/Documentation:
|
84
129
|
Exclude:
|
85
|
-
- '
|
86
|
-
- '
|
130
|
+
- '**/*.md'
|
131
|
+
- '**/*.markdown'
|
87
132
|
- 'lib/debug_logging.rb'
|
88
133
|
- 'lib/debug_logging/argument_printer.rb'
|
89
134
|
- 'lib/debug_logging/class_logger.rb'
|
@@ -96,7 +141,7 @@ Style/Documentation:
|
|
96
141
|
- 'lib/debug_logging/log_subscriber.rb'
|
97
142
|
- 'lib/simple_debug_logging.rb'
|
98
143
|
|
99
|
-
# Offense count:
|
144
|
+
# Offense count: 2
|
100
145
|
# Cop supports --auto-correct.
|
101
146
|
# Configuration parameters: EnforcedStyle.
|
102
147
|
# SupportedStyles: empty, nil, both
|
@@ -105,14 +150,7 @@ Style/EmptyElse:
|
|
105
150
|
- 'lib/debug_logging/class_logger.rb'
|
106
151
|
- 'lib/debug_logging/class_notifier.rb'
|
107
152
|
|
108
|
-
# Offense count:
|
109
|
-
# Configuration parameters: EnforcedStyle.
|
110
|
-
# SupportedStyles: annotated, template, unannotated
|
111
|
-
Style/FormatStringToken:
|
112
|
-
Exclude:
|
113
|
-
- 'lib/debug_logging/argument_printer.rb'
|
114
|
-
|
115
|
-
# Offense count: 4
|
153
|
+
# Offense count: 8
|
116
154
|
Style/IdenticalConditionalBranches:
|
117
155
|
Exclude:
|
118
156
|
- 'lib/debug_logging/class_logger.rb'
|
@@ -120,14 +158,10 @@ Style/IdenticalConditionalBranches:
|
|
120
158
|
- 'lib/debug_logging/instance_logger_modulizer.rb'
|
121
159
|
- 'lib/debug_logging/instance_notifier_modulizer.rb'
|
122
160
|
|
123
|
-
# Offense count:
|
124
|
-
Style/MultilineBlockChain:
|
125
|
-
Exclude:
|
126
|
-
- 'lib/debug_logging/argument_printer.rb'
|
127
|
-
|
128
|
-
# Offense count: 95
|
161
|
+
# Offense count: 67
|
129
162
|
# Cop supports --auto-correct.
|
130
163
|
# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
131
164
|
# URISchemes: http, https
|
165
|
+
# IgnoredPatterns: (?-mix:^\#)
|
132
166
|
Layout/LineLength:
|
133
|
-
Max:
|
167
|
+
Max: 207
|
data/.travis.yml
CHANGED
@@ -9,7 +9,7 @@ before_script:
|
|
9
9
|
- ./cc-test-reporter before-build
|
10
10
|
|
11
11
|
script:
|
12
|
-
- bundle exec rubocop -DESP
|
12
|
+
- bundle exec rubocop -DESP
|
13
13
|
- bundle exec rspec
|
14
14
|
|
15
15
|
after_script:
|
@@ -33,4 +33,4 @@ rvm:
|
|
33
33
|
- ruby-2.4.10
|
34
34
|
- ruby-2.5.8
|
35
35
|
- ruby-2.6.6
|
36
|
-
- ruby-2.7.
|
36
|
+
- ruby-2.7.2
|
data/README.md
CHANGED
@@ -1,6 +1,13 @@
|
|
1
1
|
# DebugLogging
|
2
2
|
|
3
3
|
Unobtrusive, inheritable-overridable-configurable, drop-in debug logging, that won't leave a mess behind when it is time to remove it.
|
4
|
+
Supports ActiveSupport::Notifications (thanks [@jgillson](https://github.com/jgillson)). Optional ActiveRecord callback-style hooks that you can decorate your methods with. Hooks logic was taken from the [`slippy_method_hooks` gem](https://github.com/guckin/slippy_method_hooks), (thanks [@guckin](https://github.com/guckin)), and prefaced with `debug_` for this implementation. `DebugLogging::Finalize` is lightly modified from [this stackoverflow answer](https://stackoverflow.com/a/34559282).
|
5
|
+
|
6
|
+
## What do I mean by "unobtrusive"?
|
7
|
+
|
8
|
+
**Ugly** debug logging is added inside the body of a method, so it runs when a method is called. This can create a mess of your git history, and can even introduce new bugs to your code.
|
9
|
+
|
10
|
+
**Unobtrusive** debug logging stays out of the method, changes no logic, can't break your code, and yet it still runs when your method is called, and tells you everything you wanted to know. It doesn't mess with the git history of the method at all!
|
4
11
|
|
5
12
|
| Project | DebugLogging |
|
6
13
|
|------------------------ | ----------------------- |
|
@@ -26,12 +33,15 @@ Unobtrusive, inheritable-overridable-configurable, drop-in debug logging, that w
|
|
26
33
|
* *colorization by class/method*
|
27
34
|
* *robust argument printer with customizable ellipsis*
|
28
35
|
* *unique invocation identifiers*
|
29
|
-
* *single line config, per class/instance/method config*
|
30
|
-
* *separate
|
36
|
+
* *simple single line global config, or per class/instance/method config*
|
37
|
+
* *separate loggers, if needed*
|
31
38
|
* *log method calls, also when exit scope*
|
32
39
|
* *Prevents heavy computation of strings with `logger.debug { 'log me' }` block format, since v1.0.12*
|
33
|
-
* *ActiveSupport::Notifications integration for instrumenting/logging events on class and instance methods, since v3.1*
|
34
|
-
* *Optional instance variable logging,
|
40
|
+
* *ActiveSupport::Notifications integration for instrumenting/logging events on class and instance methods, since v3.1.3*
|
41
|
+
* *Optional instance, and class-instance, variable logging, since v3.1.3*
|
42
|
+
* *ActiveRecord style callback-hooks (optional: `require 'debug_logging/hooks'` and `include DebugLogging::Hooks`), since v3.1.3*
|
43
|
+
* *All configuration is inheritable to, and overridable by, child classes, since v3.1.3*
|
44
|
+
* *[Class finalization hook](https://stackoverflow.com/a/34559282) (optional: `require 'debug_logging/finalize'` and `extend DebugLogging::Finalize`), since v3.1.3*
|
35
45
|
* **so many free ponies** 🎠🐴🎠🐴🎠🐴
|
36
46
|
|
37
47
|
## Next Level Magic
|
@@ -43,9 +53,9 @@ Herein you will find:
|
|
43
53
|
* 100% clean, 0% obtrusive
|
44
54
|
* 100% tested
|
45
55
|
* 100% Ruby 2.1+ compatible
|
46
|
-
- use version
|
47
|
-
- use version
|
48
|
-
- use version
|
56
|
+
- use version `gem "debug_logging", "~> 1.0"` for Ruby < 2.3
|
57
|
+
- use version `gem "debug_logging", "~> 2.0"` for Ruby 2.3
|
58
|
+
- use version `gem "debug_logging", "~> 3.0"` for Ruby 2.4+
|
49
59
|
|
50
60
|
NOTE: The manner this is made to work for class methods is totally different than the way this is made to work for instance methods.
|
51
61
|
|
@@ -80,7 +90,7 @@ Recommend creating `config/initializers/debug_logging.rb`, or adding to `config/
|
|
80
90
|
|
81
91
|
```ruby
|
82
92
|
# Showing the defaults
|
83
|
-
DebugLogging.configuration.logger = Logger.new(
|
93
|
+
DebugLogging.configuration.logger = Logger.new($stdout) # you probably want to override to be the Rails.logger, and if so you can't set it in the initializer, as it needs to be set after Rails.logger is set.
|
84
94
|
DebugLogging.configuration.log_level = :debug # at what level do the messages created by this gem sent at?
|
85
95
|
DebugLogging.configuration.multiple_last_hashes = false # pass every hash argument to last_hash_to_s_proc?
|
86
96
|
DebugLogging.configuration.last_hash_to_s_proc = nil # e.g. ->(hash) { "keys: #{hash.keys}" }
|
@@ -92,7 +102,7 @@ DebugLogging.configuration.active_support_notifications = false
|
|
92
102
|
DebugLogging.configuration.colorized_chain_for_method = false # e.g. ->(colorized_string) { colorized_string.red.on_blue.underline }
|
93
103
|
DebugLogging.configuration.colorized_chain_for_class = false # e.g. ->(colorized_string) { colorized_string.colorize(:light_blue ).colorize( :background => :red) }
|
94
104
|
DebugLogging.configuration.add_invocation_id = true # identify a method call uniquely in a log, pass a proc for colorization, e.g. ->(colorized_string) { colorized_string.light_black }
|
95
|
-
DebugLogging.configuration.ellipsis =
|
105
|
+
DebugLogging.configuration.ellipsis = ' ✂️ …'.freeze
|
96
106
|
DebugLogging.configuration.mark_scope_exit = true # Only has an effect if benchmarking is off, since benchmarking always marks the scope exit
|
97
107
|
```
|
98
108
|
|
@@ -100,7 +110,7 @@ If you prefer to use the block style:
|
|
100
110
|
|
101
111
|
```ruby
|
102
112
|
DebugLogging.configure do |config|
|
103
|
-
config.logger = Logger.new(
|
113
|
+
config.logger = Logger.new($stdout) # probably want to override to be the Rails.logger, and if so you can't set it in the initializer, as it needs to be set after Rails.logger is set.
|
104
114
|
config.log_level = :debug # at what level do the messages created by this gem sent at?
|
105
115
|
config.multiple_last_hashes = false # pass every hash argument to last_hash_to_s_proc?
|
106
116
|
config.last_hash_to_s_proc = nil # e.g. ->(hash) { "keys: #{hash.keys}" }
|
@@ -112,7 +122,7 @@ DebugLogging.configure do |config|
|
|
112
122
|
config.colorized_chain_for_method = false # e.g. ->(colorized_string) { colorized_string.red.on_blue.underline }
|
113
123
|
config.colorized_chain_for_class = false # e.g. ->(colorized_string) { colorized_string.colorize(:light_blue ).colorize( :background => :red) }
|
114
124
|
config.add_invocation_id = true # identify a method call uniquely in a log, pass a proc for colorization, e.g. ->(colorized_string) { colorized_string.light_black }
|
115
|
-
config.ellipsis =
|
125
|
+
config.ellipsis = ' ✂️ …'.freeze
|
116
126
|
config.mark_scope_exit = true # Only has an effect if benchmarking is off, since benchmarking always marks the scope exit
|
117
127
|
end
|
118
128
|
```
|
@@ -136,42 +146,83 @@ Every time a method is called, you can now get logs, optionally with arguments,
|
|
136
146
|
|
137
147
|
```ruby
|
138
148
|
class Car
|
139
|
-
|
140
|
-
#
|
141
|
-
# except for the logged
|
149
|
+
# Adds the helper methods to the class.
|
150
|
+
# All helpers prefixed with debug_*,
|
151
|
+
# except for the *logged* decorator, which comes from extending DebugLogging::ClassLogger
|
142
152
|
extend DebugLogging
|
143
153
|
|
144
154
|
# per class configuration overrides!
|
145
155
|
self.debug_class_benchmarks = true
|
146
156
|
self.debug_instance_benchmarks = true
|
147
157
|
|
148
|
-
# For
|
149
|
-
#
|
150
|
-
|
151
|
-
|
152
|
-
# Provides the `logged` method decorator
|
158
|
+
# For class methods
|
159
|
+
# Provides the versatile `logged` method decorator / macro
|
160
|
+
# For instance methods
|
161
|
+
# Provides the versatile `i_logged` method decorator / macro
|
153
162
|
extend DebugLogging::ClassLogger
|
154
163
|
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
def
|
164
|
+
# == BEGIN CLASS METHODS ==
|
165
|
+
# For class methods:
|
166
|
+
# Option 1: Use *logged* as a method decorator
|
167
|
+
logged def self.make
|
168
|
+
new
|
169
|
+
end
|
170
|
+
def self.design(*_args)
|
171
|
+
new
|
172
|
+
end
|
173
|
+
|
174
|
+
def self.safety(*_args)
|
175
|
+
new
|
176
|
+
end
|
177
|
+
|
178
|
+
def self.dealer_options(*_args)
|
179
|
+
new
|
180
|
+
end
|
181
|
+
|
182
|
+
# Option 2: Use *logged* as a macro
|
159
183
|
logged :design, :safety
|
160
|
-
#
|
161
|
-
|
184
|
+
# Override configuration options for any class method(s), by passing a hash as the last argument
|
185
|
+
# In the last hash any non-Configuration keys will be data that gets logged,
|
186
|
+
# and also made available to last_hash_to_s_proc
|
187
|
+
logged :dealer_options, {
|
188
|
+
something: 'here', # <= will be logged, and available to last_hash_to_s_proc
|
189
|
+
multiple_last_hashes: true # <= Overrides config
|
190
|
+
}
|
191
|
+
def self.will_not_be_logged
|
192
|
+
false
|
193
|
+
end
|
194
|
+
# == END CLASS METHODS ==
|
195
|
+
|
196
|
+
# == BEGIN INSTANCE METHODS ==
|
197
|
+
# For instance methods:
|
198
|
+
# Option 1: specify the exact method(s) to add logging to
|
199
|
+
include DebugLogging::InstanceLogger.new(i_methods: %i[drive stop])
|
200
|
+
|
201
|
+
def drive(speed)
|
202
|
+
speed
|
203
|
+
end
|
162
204
|
|
163
|
-
def
|
164
|
-
|
205
|
+
def stop(**_opts)
|
206
|
+
0
|
207
|
+
end
|
165
208
|
|
166
209
|
# For instance methods:
|
167
210
|
# Option 2: add logging to all instance methods defined above (but *not* defined below)
|
168
|
-
include DebugLogging::InstanceLogger.new(i_methods:
|
211
|
+
include DebugLogging::InstanceLogger.new(i_methods: instance_methods(false))
|
169
212
|
|
170
|
-
|
171
|
-
|
213
|
+
def faster(**_opts)
|
214
|
+
0
|
215
|
+
end
|
172
216
|
|
173
|
-
|
217
|
+
# Override configuration options for any instance method(s), by passing a hash as the last argument
|
218
|
+
# In the last hash any non-Configuration keys will be data that gets logged,
|
219
|
+
# and also made available to last_hash_to_s_proc
|
220
|
+
include DebugLogging::InstanceLogger.new(i_methods: [:faster], config: { add_invocation_id: false })
|
174
221
|
|
222
|
+
def will_not_be_logged
|
223
|
+
false
|
224
|
+
end
|
225
|
+
# == END INSTANCE METHODS ==
|
175
226
|
end
|
176
227
|
```
|
177
228
|
|
@@ -195,37 +246,82 @@ Every time a method is called, class and instance method events are instrumented
|
|
195
246
|
|
196
247
|
```ruby
|
197
248
|
class Car
|
198
|
-
|
199
|
-
#
|
200
|
-
# except for the
|
249
|
+
# Adds the helper methods to the class.
|
250
|
+
# All helpers prefixed with debug_*,
|
251
|
+
# except for the *notifies* decorator, which comes from extending DebugLogging::ClassNotifier
|
201
252
|
extend DebugLogging
|
202
253
|
|
203
254
|
# For instance methods:
|
204
|
-
# Option 1: specify the exact method(s) to add instrumentation to
|
255
|
+
# Option 1: specify the exact method(s) to add instrumentation to
|
256
|
+
# NOTE: You can capture instance variable values as part of the event payload
|
205
257
|
include DebugLogging::InstanceNotifier.new(i_methods: [:drive,
|
206
258
|
:stop,
|
207
259
|
[:turn, { instance_variables: %i[direction angle] }]])
|
208
260
|
|
209
|
-
#
|
261
|
+
# For class methods
|
262
|
+
# Provides the versatile `notifies` method decorator / macro
|
263
|
+
# For instance methods
|
264
|
+
# Provides the versatile `i_notifies` method decorator / macro
|
210
265
|
extend DebugLogging::ClassNotifier
|
211
266
|
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
def
|
267
|
+
# == BEGIN CLASS METHODS ==
|
268
|
+
# For class methods:
|
269
|
+
# Option 1: Use *notifies* as a method decorator
|
270
|
+
notifies def self.make
|
271
|
+
new
|
272
|
+
end
|
273
|
+
def self.design(*_args)
|
274
|
+
new
|
275
|
+
end
|
276
|
+
|
277
|
+
def self.safety(*_args)
|
278
|
+
new
|
279
|
+
end
|
280
|
+
|
281
|
+
def self.dealer_options(*_args)
|
282
|
+
new
|
283
|
+
end
|
284
|
+
|
285
|
+
# Option 2: Use *logged* as a macro
|
216
286
|
notifies :design, :safety
|
217
|
-
#
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
287
|
+
# Override configuration options for any class method(s), by passing a hash as the last argument
|
288
|
+
# In the last hash any non-Configuration keys will be data that gets added to the event payload,
|
289
|
+
# and also made available to last_hash_to_s_proc
|
290
|
+
notifies :dealer_options, {
|
291
|
+
something: 'here', # <= will be added to the event payload, and be available to last_hash_to_s_proc
|
292
|
+
add_invocation_id: false # <= Overrides config
|
293
|
+
}
|
294
|
+
def self.will_not_be_notified
|
295
|
+
false
|
296
|
+
end
|
297
|
+
# == END CLASS METHODS ==
|
298
|
+
|
299
|
+
# == BEGIN INSTANCE METHODS ==
|
300
|
+
def drive(speed)
|
301
|
+
speed
|
302
|
+
end
|
303
|
+
|
304
|
+
def stop(**_opts)
|
305
|
+
0
|
306
|
+
end
|
222
307
|
|
223
308
|
# For instance methods:
|
224
309
|
# Option 2: add instrumentation to all instance methods defined above (but *not* defined below)
|
225
|
-
include DebugLogging::InstanceNotifier.new(i_methods:
|
310
|
+
include DebugLogging::InstanceNotifier.new(i_methods: instance_methods(false))
|
226
311
|
|
227
|
-
def
|
312
|
+
def faster(**_opts)
|
313
|
+
0
|
314
|
+
end
|
228
315
|
|
316
|
+
# Override options for any instance method(s), by passing a hash as the last argument
|
317
|
+
# In the last hash any non-Configuration keys will be data that gets added to the event payload,
|
318
|
+
# and also made available to last_hash_to_s_proc
|
319
|
+
include DebugLogging::InstanceNotifier.new(i_methods: [:faster], config: { add_invocation_id: false })
|
320
|
+
|
321
|
+
def will_not_be_notified
|
322
|
+
false
|
323
|
+
end
|
324
|
+
# == END INSTANCE METHODS ==
|
229
325
|
end
|
230
326
|
```
|
231
327
|
|
@@ -289,6 +385,10 @@ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
289
385
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
290
386
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
291
387
|
|
388
|
+
### License Exceptions
|
389
|
+
|
390
|
+
* [`debug_logging/finalize`](https://stackoverflow.com/a/34559282) is licensed under https://creativecommons.org/licenses/by-sa/4.0/
|
391
|
+
|
292
392
|
[semver]: http://semver.org/
|
293
393
|
[pvc]: http://docs.rubygems.org/read/chapter/16#page74
|
294
394
|
[railsbling]: http://www.railsbling.com
|