debug_logging 3.0.0 → 3.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cab0a0dee00124b49ff568d1b1f8dbeaee9ba25b975af8d3fa1f0b4d3af88054
4
- data.tar.gz: f8427104b804d23a284edd3ab8878c96273e8edf4dec850ae3001c15a60bf6ed
3
+ metadata.gz: c3b22568d767ce27e04784bc0c5884d256dac350db70c0a55e4c3d0111b00e4b
4
+ data.tar.gz: a3d0a5b1fa588b2b9c7596ce52e3e46b04724a460cf825c1393c0bd358117fc2
5
5
  SHA512:
6
- metadata.gz: e871fdb1af74fe7b17c5e66b918edcec67d696b4d45b9bca79025b2a9c35c41a42aa1c8794bd0184aacf34e39ce4c43348ed6b6b96e6d17abb180db10fcabc3b
7
- data.tar.gz: 389312d99d1060d3349bf8f9a1e05a579dfeaf17c40151d1670483152da18c043a4a2b401749dad884b99b9acf3042dcc75e61189e0fc7141ca41d28bac6f264
6
+ metadata.gz: bd581ea6179d7cc21fa501f0ab7870a2e9d25a664ae544999aa0f703fc351955b7fb5a6c1eacafb3946dd6dde7e6c246a3bebac37af07572c21adc4d0a169e15
7
+ data.tar.gz: a6ae636072c6e60d19831b4ffa1012b4d7dfd1c67a7e78384f7ad6c004e57e729f83dcd24043938a0c03049722fe477bef7ed4ac9c7bce9c7e80ffc76b48e698
@@ -1,3 +1,11 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
3
+ require:
4
+ - 'rubocop-md'
5
+ - 'rubocop-performance'
6
+ - 'rubocop-rake'
7
+ - 'rubocop-rspec'
8
+
1
9
  AllCops:
2
10
  NewCops: enable
3
11
 
@@ -1,126 +1,167 @@
1
- inherit_from: .rubocop.yml
2
-
3
1
  # This configuration was generated by
4
2
  # `rubocop --auto-gen-config`
5
- # on 2020-10-06 07:34:51 UTC using RuboCop version 0.92.0.
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: 1
12
- # Configuration parameters: Include.
13
- # Include: **/*.gemspec
14
- Gemspec/RequiredRubyVersion:
9
+ # Offense count: 7
10
+ Lint/DuplicateMethods:
15
11
  Exclude:
16
- - 'debug_logging.gemspec'
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: 5
28
- # Configuration parameters: IgnoredMethods.
14
+ # Offense count: 6
15
+ # Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
29
16
  Metrics/AbcSize:
30
- Max: 97
17
+ Max: 96
31
18
 
32
- # Offense count: 38
33
- # Configuration parameters: CountComments, CountAsOne, ExcludedMethods.
34
- # ExcludedMethods: refine
19
+ # Offense count: 58
20
+ # Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
21
+ # IgnoredMethods: refine
35
22
  Metrics/BlockLength:
36
- Max: 756
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: 22
33
+ Max: 24
52
34
 
53
- # Offense count: 11
54
- # Configuration parameters: CountComments, CountAsOne, ExcludedMethods.
35
+ # Offense count: 15
36
+ # Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
55
37
  Metrics/MethodLength:
56
- Max: 50
38
+ Max: 75
57
39
 
58
- # Offense count: 1
40
+ # Offense count: 2
59
41
  # Configuration parameters: CountComments, CountAsOne.
60
42
  Metrics/ModuleLength:
61
43
  Max: 112
62
44
 
63
- # Offense count: 4
45
+ # Offense count: 5
64
46
  # Configuration parameters: IgnoredMethods.
65
47
  Metrics/PerceivedComplexity:
66
- Max: 26
48
+ Max: 31
67
49
 
68
- # Offense count: 1
69
- # Configuration parameters: AllowedChars.
70
- Style/AsciiComments:
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
- # Cop supports --auto-correct.
76
- # Configuration parameters: EnforcedStyle, SingleLineConditionsOnly, IncludeTernaryExpressions.
77
- # SupportedStyles: assign_to_condition, assign_inside_condition
78
- Style/ConditionalAssignment:
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
- - 'lib/debug_logging/argument_printer.rb'
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: 9
127
+ # Offense count: 13
83
128
  Style/Documentation:
84
129
  Exclude:
85
- - 'spec/**/*'
86
- - 'test/**/*'
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'
135
+ - 'lib/debug_logging/class_notifier.rb'
90
136
  - 'lib/debug_logging/configuration.rb'
91
137
  - 'lib/debug_logging/instance_logger.rb'
92
138
  - 'lib/debug_logging/instance_logger_modulizer.rb'
139
+ - 'lib/debug_logging/instance_notifier.rb'
140
+ - 'lib/debug_logging/instance_notifier_modulizer.rb'
141
+ - 'lib/debug_logging/log_subscriber.rb'
93
142
  - 'lib/simple_debug_logging.rb'
94
143
 
95
- # Offense count: 1
144
+ # Offense count: 2
96
145
  # Cop supports --auto-correct.
97
146
  # Configuration parameters: EnforcedStyle.
98
147
  # SupportedStyles: empty, nil, both
99
148
  Style/EmptyElse:
100
149
  Exclude:
101
150
  - 'lib/debug_logging/class_logger.rb'
151
+ - 'lib/debug_logging/class_notifier.rb'
102
152
 
103
- # Offense count: 2
104
- # Configuration parameters: EnforcedStyle.
105
- # SupportedStyles: annotated, template, unannotated
106
- Style/FormatStringToken:
107
- Exclude:
108
- - 'lib/debug_logging/argument_printer.rb'
109
-
110
- # Offense count: 4
153
+ # Offense count: 8
111
154
  Style/IdenticalConditionalBranches:
112
155
  Exclude:
113
156
  - 'lib/debug_logging/class_logger.rb'
157
+ - 'lib/debug_logging/class_notifier.rb'
114
158
  - 'lib/debug_logging/instance_logger_modulizer.rb'
159
+ - 'lib/debug_logging/instance_notifier_modulizer.rb'
115
160
 
116
- # Offense count: 1
117
- Style/MultilineBlockChain:
118
- Exclude:
119
- - 'lib/debug_logging/argument_printer.rb'
120
-
121
- # Offense count: 95
161
+ # Offense count: 67
122
162
  # Cop supports --auto-correct.
123
163
  # Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
124
164
  # URISchemes: http, https
165
+ # IgnoredPatterns: (?-mix:^\#)
125
166
  Layout/LineLength:
126
- Max: 223
167
+ Max: 207
@@ -9,7 +9,7 @@ before_script:
9
9
  - ./cc-test-reporter before-build
10
10
 
11
11
  script:
12
- - bundle exec rubocop -DESP --config ./.rubocop_todo.yml
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.1
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,10 +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 logger, if needed*
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
- * *Prevents heavy computation of strings with `logger.debug { 'log me' }` block format.*
39
+ * *Prevents heavy computation of strings with `logger.debug { 'log me' }` block format, since v1.0.12*
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*
33
45
  * **so many free ponies** 🎠🐴🎠🐴🎠🐴
34
46
 
35
47
  ## Next Level Magic
@@ -40,7 +52,10 @@ Herein you will find:
40
52
  * Zero tolerance policy on monkey patching
41
53
  * 100% clean, 0% obtrusive
42
54
  * 100% tested
43
- * 100% Ruby 2.3+ compatible
55
+ * 100% Ruby 2.1+ compatible
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+
44
59
 
45
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.
46
61
 
@@ -62,8 +77,6 @@ Or install it yourself as:
62
77
 
63
78
  ## Usage
64
79
 
65
- NOTE: Starting with version `1.0.12` this gem utilizes the `logger.debug { "block format" }` to avoid heavy debug processing when the log level threshold is set higher than the level of the statements produced as a result of the configuration of this gem.
66
-
67
80
  Crack open the specs for more complex usage examples than the ones below.
68
81
 
69
82
  ### Without Rails
@@ -77,7 +90,7 @@ Recommend creating `config/initializers/debug_logging.rb`, or adding to `config/
77
90
 
78
91
  ```ruby
79
92
  # Showing the defaults
80
- 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.
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.
81
94
  DebugLogging.configuration.log_level = :debug # at what level do the messages created by this gem sent at?
82
95
  DebugLogging.configuration.multiple_last_hashes = false # pass every hash argument to last_hash_to_s_proc?
83
96
  DebugLogging.configuration.last_hash_to_s_proc = nil # e.g. ->(hash) { "keys: #{hash.keys}" }
@@ -85,10 +98,11 @@ DebugLogging.configuration.last_hash_max_length = 1_000
85
98
  DebugLogging.configuration.args_max_length = 1_000
86
99
  DebugLogging.configuration.instance_benchmarks = false
87
100
  DebugLogging.configuration.class_benchmarks = false
101
+ DebugLogging.configuration.active_support_notifications = false
88
102
  DebugLogging.configuration.colorized_chain_for_method = false # e.g. ->(colorized_string) { colorized_string.red.on_blue.underline }
89
103
  DebugLogging.configuration.colorized_chain_for_class = false # e.g. ->(colorized_string) { colorized_string.colorize(:light_blue ).colorize( :background => :red) }
90
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 }
91
- DebugLogging.configuration.ellipsis = " ✂️ …".freeze
105
+ DebugLogging.configuration.ellipsis = ' ✂️ …'.freeze
92
106
  DebugLogging.configuration.mark_scope_exit = true # Only has an effect if benchmarking is off, since benchmarking always marks the scope exit
93
107
  ```
94
108
 
@@ -96,7 +110,7 @@ If you prefer to use the block style:
96
110
 
97
111
  ```ruby
98
112
  DebugLogging.configure do |config|
99
- 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.
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.
100
114
  config.log_level = :debug # at what level do the messages created by this gem sent at?
101
115
  config.multiple_last_hashes = false # pass every hash argument to last_hash_to_s_proc?
102
116
  config.last_hash_to_s_proc = nil # e.g. ->(hash) { "keys: #{hash.keys}" }
@@ -104,10 +118,11 @@ DebugLogging.configure do |config|
104
118
  config.args_max_length = 1_000
105
119
  config.instance_benchmarks = false
106
120
  config.class_benchmarks = false
121
+ config.active_support_notifications = false
107
122
  config.colorized_chain_for_method = false # e.g. ->(colorized_string) { colorized_string.red.on_blue.underline }
108
123
  config.colorized_chain_for_class = false # e.g. ->(colorized_string) { colorized_string.colorize(:light_blue ).colorize( :background => :red) }
109
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 }
110
- config.ellipsis = " ✂️ …".freeze
125
+ config.ellipsis = ' ✂️ …'.freeze
111
126
  config.mark_scope_exit = true # Only has an effect if benchmarking is off, since benchmarking always marks the scope exit
112
127
  end
113
128
  ```
@@ -127,46 +142,186 @@ Just send along a hash of the config options when you call `logged` or `include
127
142
  DebugLogging.configuration.logger = Rails.logger
128
143
  ```
129
144
 
130
- Every time a method is called, get logs, optionally with arguments, a benchmarck, and a unique invocation identifier:
145
+ Every time a method is called, you can now get logs, optionally with arguments, a benchmark, and a unique invocation identifier:
131
146
 
132
147
  ```ruby
133
148
  class Car
134
-
135
- # adds the helper methods to the class, all are prefixed with debug_*,
136
- # except for the logged class method, which comes from extending DebugLogging::ClassLogger
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
137
152
  extend DebugLogging
138
153
 
139
154
  # per class configuration overrides!
140
155
  self.debug_class_benchmarks = true
141
156
  self.debug_instance_benchmarks = true
142
157
 
143
- # For instance methods:
144
- # Option 1: specify the exact method(s) to add logging to
145
- include DebugLogging::InstanceLogger.new(i_methods: [:drive, :stop])
146
-
147
- # 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
148
162
  extend DebugLogging::ClassLogger
149
163
 
150
- logged def make; new; end
151
- def design(*args); new; end
152
- def safety(*args); new; end
153
- def dealer_options(*args); new; end
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
154
183
  logged :design, :safety
155
- # override options for any instance method(s), by passing a hash as the last argument
156
- logged :dealer_options, { multiple_last_hashes: true }
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
157
204
 
158
- def drive(speed); speed; end
159
- def stop(**opts); 0; end
205
+ def stop(**_opts)
206
+ 0
207
+ end
160
208
 
161
209
  # For instance methods:
162
210
  # Option 2: add logging to all instance methods defined above (but *not* defined below)
163
- include DebugLogging::InstanceLogger.new(i_methods: self.instance_methods(false))
211
+ include DebugLogging::InstanceLogger.new(i_methods: instance_methods(false))
164
212
 
165
- # override options for any instance method(s)
166
- include DebugLogging::InstanceLogger.new(i_methods: [:stop], config: { multiple_last_hashes: true })
213
+ def faster(**_opts)
214
+ 0
215
+ end
167
216
 
168
- def will_not_be_logged; false; end
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 })
169
221
 
222
+ def will_not_be_logged
223
+ false
224
+ end
225
+ # == END INSTANCE METHODS ==
226
+ end
227
+ ```
228
+
229
+ ### ActiveSupport::Notifications integration
230
+
231
+ To use `ActiveSupport::Notifications` integration, enable `active_support_notifications` in the config, either single line or block style:
232
+
233
+ ```ruby
234
+ DebugLogging.configuration.active_support_notifications = true
235
+ ```
236
+
237
+ or
238
+
239
+ ```ruby
240
+ DebugLogging.configure do |config|
241
+ config.active_support_notifications = true
242
+ end
243
+ ```
244
+
245
+ Every time a method is called, class and instance method events are instrumented, consumed and logged:
246
+
247
+ ```ruby
248
+ class Car
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
252
+ extend DebugLogging
253
+
254
+ # For instance methods:
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
257
+ include DebugLogging::InstanceNotifier.new(i_methods: [:drive,
258
+ :stop,
259
+ [:turn, { instance_variables: %i[direction angle] }]])
260
+
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
265
+ extend DebugLogging::ClassNotifier
266
+
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
286
+ notifies :design, :safety
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
307
+
308
+ # For instance methods:
309
+ # Option 2: add instrumentation to all instance methods defined above (but *not* defined below)
310
+ include DebugLogging::InstanceNotifier.new(i_methods: instance_methods(false))
311
+
312
+ def faster(**_opts)
313
+ 0
314
+ end
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 ==
170
325
  end
171
326
  ```
172
327
 
@@ -202,7 +357,7 @@ dependency on this gem using the [Pessimistic Version Constraint](http://docs.ru
202
357
  For example:
203
358
 
204
359
  ```ruby
205
- spec.add_dependency 'debug_logging', '~> 2.0'
360
+ spec.add_dependency 'debug_logging', '~> 3.1'
206
361
  ```
207
362
 
208
363
  ## License [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)
@@ -230,6 +385,10 @@ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
230
385
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
231
386
  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
232
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
+
233
392
  [semver]: http://semver.org/
234
393
  [pvc]: http://docs.rubygems.org/read/chapter/16#page74
235
394
  [railsbling]: http://www.railsbling.com