debug_logging 2.0.0 → 3.1.3
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 +104 -63
- data/.travis.yml +2 -3
- data/README.md +193 -34
- data/debug_logging.gemspec +8 -4
- data/lib/debug_logging.rb +9 -0
- data/lib/debug_logging/active_support_notifications.rb +6 -0
- data/lib/debug_logging/argument_printer.rb +48 -11
- data/lib/debug_logging/class_logger.rb +32 -27
- data/lib/debug_logging/class_notifier.rb +54 -0
- data/lib/debug_logging/configuration.rb +55 -49
- 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 +22 -0
- data/lib/debug_logging/instance_notifier_modulizer.rb +47 -0
- data/lib/debug_logging/log_subscriber.rb +43 -0
- data/lib/debug_logging/util.rb +75 -0
- data/lib/debug_logging/version.rb +1 -1
- data/lib/simple_debug_logging.rb +2 -2
- metadata +82 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6eee794d14ae44299b2737ff61beab4165c434132262861104d60b4da781445
|
4
|
+
data.tar.gz: c9fdb194a05fa751879a60bb73bd4eb3fe4507b0680b1ee437f5d88fa65b3fa0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8eeb20c2a01e99b3069f8b592f54271497a6835402e76d73edba964645c2b6600e83e3d497b7eddf5720087b89421e61caa7e5224124f5205fdde6f0b82d5426
|
7
|
+
data.tar.gz: fce74d216e19def9b2e8b208036138732fc82add3e889fdd3a09199dab285354c5863b1a11b12feb451faa9e39294507ec704e40031568272ac03a6c1be13077
|
data/.rubocop.yml
CHANGED
data/.rubocop_todo.yml
CHANGED
@@ -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
|
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'
|
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:
|
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:
|
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:
|
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:
|
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:
|
@@ -30,8 +30,7 @@ language: ruby
|
|
30
30
|
sudo: false
|
31
31
|
|
32
32
|
rvm:
|
33
|
-
- ruby-2.3.8
|
34
33
|
- ruby-2.4.10
|
35
34
|
- ruby-2.5.8
|
36
35
|
- ruby-2.6.6
|
37
|
-
- ruby-2.7.
|
36
|
+
- ruby-2.7.2
|
data/README.md
CHANGED
@@ -1,11 +1,18 @@
|
|
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
|
|------------------------ | ----------------------- |
|
7
14
|
| gem name | [debug_logging](https://rubygems.org/gems/debug_logging) |
|
8
|
-
| compatibility | Ruby 2.
|
15
|
+
| compatibility | Ruby 2.4, 2.5, 2.6, 2.7 |
|
9
16
|
| license | [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT) |
|
10
17
|
| download rank | [![Downloads Today](https://img.shields.io/gem/rd/debug_logging.svg)](https://github.com/pboling/debug_logging) |
|
11
18
|
| version | [![Version](https://img.shields.io/gem/v/debug_logging.svg)](https://rubygems.org/gems/debug_logging) |
|
@@ -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
|
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.2*
|
41
|
+
* *Optional instance, and class-instance, variable logging, since v3.2*
|
42
|
+
* *ActiveRecord style callback-hooks (optional: `require 'debug_logging/hooks'` and `include DebugLogging::Hooks`), since v3.2*
|
43
|
+
* *All configuration is inheritable to, and overridable by, child classes, since v3.2*
|
44
|
+
* *[Class finalization hook](https://stackoverflow.com/a/34559282) (optional: `require 'debug_logging/finalize'` and `extend DebugLogging::Finalize`), since v3.2*
|
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.
|
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(
|
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 =
|
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(
|
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 =
|
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
|
```
|
@@ -119,7 +134,7 @@ Just prepend `debug_` to any config value you want to override in a class.
|
|
119
134
|
Just prepend `debug_` to any config value you want to override on an instance of a class.
|
120
135
|
|
121
136
|
**All** of the above **config** is **inheritable** and **configurable** at the **per-method** level as well!
|
122
|
-
Just send along a hash of the config options when you call `logged` or `include DebugLogging::InstanceLogger.new(i_methods: [:drive, :stop], config: { ellipsis
|
137
|
+
Just send along a hash of the config options when you call `logged` or `include DebugLogging::InstanceLogger.new(i_methods: [:drive, :stop], config: { ellipsis: " ✂️ 2 much" })`. See the example class below, and the specs.
|
123
138
|
|
124
139
|
**NOTE ON** `Rails.logger` - It will probably be nil in your initializer, so setting the `config.logger` to `Rails.logger` there will result in setting it to `nil`, which means the default will end up being used: `Logger.new(STDOUT)`. Instead just config the logger in your application.rb, or anytime later, but *before your classes get loaded* and start inheriting the config:
|
125
140
|
|
@@ -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
|
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
|
-
#
|
136
|
-
# 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
|
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
|
144
|
-
#
|
145
|
-
|
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
|
-
|
151
|
-
|
152
|
-
|
153
|
-
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
|
154
183
|
logged :design, :safety
|
155
|
-
#
|
156
|
-
|
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
|
159
|
-
|
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:
|
211
|
+
include DebugLogging::InstanceLogger.new(i_methods: instance_methods(false))
|
164
212
|
|
165
|
-
|
166
|
-
|
213
|
+
def faster(**_opts)
|
214
|
+
0
|
215
|
+
end
|
167
216
|
|
168
|
-
|
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', '~>
|
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
|