debug_logging 1.0.13 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.rubocop.yml +99 -0
- data/.rubocop_todo.yml +126 -0
- data/.travis.yml +35 -5
- data/Gemfile +8 -2
- data/README.md +30 -34
- data/Rakefile +5 -3
- data/bin/console +4 -3
- data/debug_logging.gemspec +23 -20
- data/lib/debug_logging.rb +48 -12
- data/lib/debug_logging/argument_printer.rb +42 -33
- data/lib/debug_logging/class_logger.rb +4 -2
- data/lib/debug_logging/configuration.rb +55 -45
- data/lib/debug_logging/instance_logger.rb +5 -0
- data/lib/debug_logging/instance_logger_modulizer.rb +4 -2
- data/lib/debug_logging/version.rb +3 -1
- data/lib/simple_debug_logging.rb +7 -3
- metadata +66 -37
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6783c4fff86c30c678b2fd856a513d3400625f7068d1735035ebd33ee42ebbc8
|
4
|
+
data.tar.gz: 86b3b4fe6d8e7476049772c250a51c5b5a9dc20f0b6988490de780ac0b24627a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bb65b3efd7beec972f818afd528e45c810dd7da0b5762a9f7f990d15d96093b9d81e7da2fa0f2dd7e7d2a925686324d1031e0b722c306593a06c6671be1c2e77
|
7
|
+
data.tar.gz: d05fad773afdfa701218f101cc97db708b726c55bda17ccd4784fbeb85d3ade6309dfe95a779afd825582c7d09883c17a2f5d4eb0d78837debde759419eae16d
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
AllCops:
|
2
|
+
NewCops: enable
|
3
|
+
|
4
|
+
Layout/BeginEndAlignment: # (new in 0.91)
|
5
|
+
Enabled: true
|
6
|
+
Layout/EmptyLinesAroundAttributeAccessor: # (new in 0.83)
|
7
|
+
Enabled: true
|
8
|
+
Layout/SpaceAroundMethodCallOperator: # (new in 0.82)
|
9
|
+
Enabled: true
|
10
|
+
Lint/BinaryOperatorWithIdenticalOperands: # (new in 0.89)
|
11
|
+
Enabled: true
|
12
|
+
Lint/ConstantDefinitionInBlock: # (new in 0.91)
|
13
|
+
Enabled: true
|
14
|
+
Lint/DeprecatedOpenSSLConstant: # (new in 0.84)
|
15
|
+
Enabled: true
|
16
|
+
Lint/DuplicateElsifCondition: # (new in 0.88)
|
17
|
+
Enabled: true
|
18
|
+
Lint/DuplicateRequire: # (new in 0.90)
|
19
|
+
Enabled: true
|
20
|
+
Lint/DuplicateRescueException: # (new in 0.89)
|
21
|
+
Enabled: true
|
22
|
+
Lint/EmptyConditionalBody: # (new in 0.89)
|
23
|
+
Enabled: true
|
24
|
+
Lint/EmptyFile: # (new in 0.90)
|
25
|
+
Enabled: true
|
26
|
+
Lint/FloatComparison: # (new in 0.89)
|
27
|
+
Enabled: true
|
28
|
+
Lint/IdentityComparison: # (new in 0.91)
|
29
|
+
Enabled: true
|
30
|
+
Lint/MissingSuper: # (new in 0.89)
|
31
|
+
Enabled: true
|
32
|
+
Lint/MixedRegexpCaptureTypes: # (new in 0.85)
|
33
|
+
Enabled: true
|
34
|
+
Lint/OutOfRangeRegexpRef: # (new in 0.89)
|
35
|
+
Enabled: true
|
36
|
+
Lint/RaiseException: # (new in 0.81)
|
37
|
+
Enabled: true
|
38
|
+
Lint/SelfAssignment: # (new in 0.89)
|
39
|
+
Enabled: true
|
40
|
+
Lint/StructNewOverride: # (new in 0.81)
|
41
|
+
Enabled: true
|
42
|
+
Lint/TopLevelReturnWithArgument: # (new in 0.89)
|
43
|
+
Enabled: true
|
44
|
+
Lint/TrailingCommaInAttributeDeclaration: # (new in 0.90)
|
45
|
+
Enabled: true
|
46
|
+
Lint/UnreachableLoop: # (new in 0.89)
|
47
|
+
Enabled: true
|
48
|
+
Lint/UselessMethodDefinition: # (new in 0.90)
|
49
|
+
Enabled: true
|
50
|
+
Lint/UselessTimes: # (new in 0.91)
|
51
|
+
Enabled: true
|
52
|
+
Style/AccessorGrouping: # (new in 0.87)
|
53
|
+
Enabled: true
|
54
|
+
Style/BisectedAttrAccessor: # (new in 0.87)
|
55
|
+
Enabled: true
|
56
|
+
Style/CaseLikeIf: # (new in 0.88)
|
57
|
+
Enabled: true
|
58
|
+
Style/CombinableLoops: # (new in 0.90)
|
59
|
+
Enabled: true
|
60
|
+
Style/ExplicitBlockArgument: # (new in 0.89)
|
61
|
+
Enabled: true
|
62
|
+
Style/ExponentialNotation: # (new in 0.82)
|
63
|
+
Enabled: true
|
64
|
+
Style/GlobalStdStream: # (new in 0.89)
|
65
|
+
Enabled: true
|
66
|
+
Style/HashAsLastArrayItem: # (new in 0.88)
|
67
|
+
Enabled: true
|
68
|
+
Style/HashEachMethods: # (new in 0.80)
|
69
|
+
Enabled: true
|
70
|
+
Style/HashLikeCase: # (new in 0.88)
|
71
|
+
Enabled: true
|
72
|
+
Style/HashTransformKeys: # (new in 0.80)
|
73
|
+
Enabled: true
|
74
|
+
Style/HashTransformValues: # (new in 0.80)
|
75
|
+
Enabled: true
|
76
|
+
Style/KeywordParametersOrder: # (new in 0.90)
|
77
|
+
Enabled: true
|
78
|
+
Style/OptionalBooleanParameter: # (new in 0.89)
|
79
|
+
Enabled: true
|
80
|
+
Style/RedundantAssignment: # (new in 0.87)
|
81
|
+
Enabled: true
|
82
|
+
Style/RedundantFetchBlock: # (new in 0.86)
|
83
|
+
Enabled: true
|
84
|
+
Style/RedundantFileExtensionInRequire: # (new in 0.88)
|
85
|
+
Enabled: true
|
86
|
+
Style/RedundantRegexpCharacterClass: # (new in 0.85)
|
87
|
+
Enabled: true
|
88
|
+
Style/RedundantRegexpEscape: # (new in 0.85)
|
89
|
+
Enabled: true
|
90
|
+
Style/RedundantSelfAssignment: # (new in 0.90)
|
91
|
+
Enabled: true
|
92
|
+
Style/SingleArgumentDig: # (new in 0.89)
|
93
|
+
Enabled: true
|
94
|
+
Style/SlicingWithRange: # (new in 0.83)
|
95
|
+
Enabled: true
|
96
|
+
Style/SoleNestedConditional: # (new in 0.89)
|
97
|
+
Enabled: true
|
98
|
+
Style/StringConcatenation: # (new in 0.89)
|
99
|
+
Enabled: true
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
inherit_from: .rubocop.yml
|
2
|
+
|
3
|
+
# This configuration was generated by
|
4
|
+
# `rubocop --auto-gen-config`
|
5
|
+
# on 2020-10-06 07:34:51 UTC using RuboCop version 0.92.0.
|
6
|
+
# The point is for the user to remove these configuration records
|
7
|
+
# one by one as the offenses are removed from the code base.
|
8
|
+
# Note that changes in the inspected code, or installation of new
|
9
|
+
# versions of RuboCop, may require this file to be generated again.
|
10
|
+
|
11
|
+
# Offense count: 1
|
12
|
+
# Configuration parameters: Include.
|
13
|
+
# Include: **/*.gemspec
|
14
|
+
Gemspec/RequiredRubyVersion:
|
15
|
+
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'
|
26
|
+
|
27
|
+
# Offense count: 5
|
28
|
+
# Configuration parameters: IgnoredMethods.
|
29
|
+
Metrics/AbcSize:
|
30
|
+
Max: 97
|
31
|
+
|
32
|
+
# Offense count: 38
|
33
|
+
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods.
|
34
|
+
# ExcludedMethods: refine
|
35
|
+
Metrics/BlockLength:
|
36
|
+
Max: 756
|
37
|
+
|
38
|
+
# Offense count: 6
|
39
|
+
# Configuration parameters: CountBlocks.
|
40
|
+
Metrics/BlockNesting:
|
41
|
+
Max: 4
|
42
|
+
|
43
|
+
# Offense count: 1
|
44
|
+
# Configuration parameters: CountComments, CountAsOne.
|
45
|
+
Metrics/ClassLength:
|
46
|
+
Max: 101
|
47
|
+
|
48
|
+
# Offense count: 4
|
49
|
+
# Configuration parameters: IgnoredMethods.
|
50
|
+
Metrics/CyclomaticComplexity:
|
51
|
+
Max: 22
|
52
|
+
|
53
|
+
# Offense count: 11
|
54
|
+
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods.
|
55
|
+
Metrics/MethodLength:
|
56
|
+
Max: 50
|
57
|
+
|
58
|
+
# Offense count: 1
|
59
|
+
# Configuration parameters: CountComments, CountAsOne.
|
60
|
+
Metrics/ModuleLength:
|
61
|
+
Max: 112
|
62
|
+
|
63
|
+
# Offense count: 4
|
64
|
+
# Configuration parameters: IgnoredMethods.
|
65
|
+
Metrics/PerceivedComplexity:
|
66
|
+
Max: 26
|
67
|
+
|
68
|
+
# Offense count: 1
|
69
|
+
# Configuration parameters: AllowedChars.
|
70
|
+
Style/AsciiComments:
|
71
|
+
Exclude:
|
72
|
+
- 'lib/debug_logging/configuration.rb'
|
73
|
+
|
74
|
+
# 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:
|
79
|
+
Exclude:
|
80
|
+
- 'lib/debug_logging/argument_printer.rb'
|
81
|
+
|
82
|
+
# Offense count: 9
|
83
|
+
Style/Documentation:
|
84
|
+
Exclude:
|
85
|
+
- 'spec/**/*'
|
86
|
+
- 'test/**/*'
|
87
|
+
- 'lib/debug_logging.rb'
|
88
|
+
- 'lib/debug_logging/argument_printer.rb'
|
89
|
+
- 'lib/debug_logging/class_logger.rb'
|
90
|
+
- 'lib/debug_logging/configuration.rb'
|
91
|
+
- 'lib/debug_logging/instance_logger.rb'
|
92
|
+
- 'lib/debug_logging/instance_logger_modulizer.rb'
|
93
|
+
- 'lib/simple_debug_logging.rb'
|
94
|
+
|
95
|
+
# Offense count: 1
|
96
|
+
# Cop supports --auto-correct.
|
97
|
+
# Configuration parameters: EnforcedStyle.
|
98
|
+
# SupportedStyles: empty, nil, both
|
99
|
+
Style/EmptyElse:
|
100
|
+
Exclude:
|
101
|
+
- 'lib/debug_logging/class_logger.rb'
|
102
|
+
|
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
|
111
|
+
Style/IdenticalConditionalBranches:
|
112
|
+
Exclude:
|
113
|
+
- 'lib/debug_logging/class_logger.rb'
|
114
|
+
- 'lib/debug_logging/instance_logger_modulizer.rb'
|
115
|
+
|
116
|
+
# Offense count: 1
|
117
|
+
Style/MultilineBlockChain:
|
118
|
+
Exclude:
|
119
|
+
- 'lib/debug_logging/argument_printer.rb'
|
120
|
+
|
121
|
+
# Offense count: 95
|
122
|
+
# Cop supports --auto-correct.
|
123
|
+
# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
124
|
+
# URISchemes: http, https
|
125
|
+
Layout/LineLength:
|
126
|
+
Max: 223
|
data/.travis.yml
CHANGED
@@ -1,7 +1,37 @@
|
|
1
|
-
|
1
|
+
env:
|
2
|
+
global:
|
3
|
+
- JRUBY_OPTS="-Xcli.debug=true --debug"
|
4
|
+
- CC_TEST_REPORTER_ID=b78cb927bf15a7aee5aacd4486215628550f784e77d137a2da8c96c417a068ff
|
5
|
+
|
6
|
+
before_script:
|
7
|
+
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
8
|
+
- chmod +x ./cc-test-reporter
|
9
|
+
- ./cc-test-reporter before-build
|
10
|
+
|
11
|
+
script:
|
12
|
+
- bundle exec rubocop -DESP --config ./.rubocop_todo.yml
|
13
|
+
- bundle exec rspec
|
14
|
+
|
15
|
+
after_script:
|
16
|
+
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
|
17
|
+
|
18
|
+
before_install:
|
19
|
+
- gem update --system
|
20
|
+
- gem install bundler
|
21
|
+
|
22
|
+
install:
|
23
|
+
- bundle install
|
24
|
+
|
25
|
+
bundler_args: --no-deployment --jobs 3 --retry 3
|
26
|
+
|
27
|
+
cache: bundler
|
28
|
+
|
2
29
|
language: ruby
|
30
|
+
sudo: false
|
31
|
+
|
3
32
|
rvm:
|
4
|
-
- ruby-2.3.
|
5
|
-
- ruby-2.4.
|
6
|
-
-
|
7
|
-
|
33
|
+
- ruby-2.3.8
|
34
|
+
- ruby-2.4.10
|
35
|
+
- ruby-2.5.8
|
36
|
+
- ruby-2.6.6
|
37
|
+
- ruby-2.7.1
|
data/Gemfile
CHANGED
@@ -1,6 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
source 'https://rubygems.org'
|
2
4
|
|
5
|
+
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
6
|
+
|
7
|
+
group :test do
|
8
|
+
gem 'coveralls', '~> 0', require: false
|
9
|
+
end
|
10
|
+
|
3
11
|
# Specify your gem's dependencies in debug_logging.gemspec
|
4
12
|
gemspec
|
5
|
-
|
6
|
-
gem 'byebug', '~> 9.0', platform: :mri
|
data/README.md
CHANGED
@@ -2,7 +2,26 @@
|
|
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
4
|
|
5
|
+
| Project | DebugLogging |
|
6
|
+
|------------------------ | ----------------------- |
|
7
|
+
| gem name | [debug_logging](https://rubygems.org/gems/debug_logging) |
|
8
|
+
| compatibility | Ruby 2.3, 2.4, 2.5, 2.6, 2.7 |
|
9
|
+
| license | [](https://opensource.org/licenses/MIT) |
|
10
|
+
| download rank | [](https://github.com/pboling/debug_logging) |
|
11
|
+
| version | [](https://rubygems.org/gems/debug_logging) |
|
12
|
+
| dependencies | [](https://depfu.com/github/pboling/debug_logging?project_id=2675) |
|
13
|
+
| continuous integration | [](https://travis-ci.org/pboling/debug_logging) |
|
14
|
+
| test coverage | [](https://codeclimate.com/github/pboling/debug_logging/test_coverage) |
|
15
|
+
| maintainability | [](https://codeclimate.com/github/pboling/debug_logging/maintainability) |
|
16
|
+
| code triage | [](https://www.codetriage.com/pboling/debug_logging) |
|
17
|
+
| homepage | [on Github.com][homepage], [on Railsbling.com][blogpage] |
|
18
|
+
| documentation | [on RDoc.info][documentation] |
|
19
|
+
| live chat | [](https://gitter.im/pboling/debug_logging?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) |
|
20
|
+
| expert support | [](https://www.codementor.io/peterboling?utm_source=github&utm_medium=button&utm_term=peterboling&utm_campaign=github) |
|
21
|
+
| Spread ~♡ⓛⓞⓥⓔ♡~ | [🌏](https://about.me/peter.boling), [👼](https://angel.co/peter-boling), [:shipit:](http://coderwall.com/pboling), [](http://twitter.com/galtzo), [🌹](https://nationalprogressiveparty.org) |
|
22
|
+
|
5
23
|
### Gives you (all are optional):
|
24
|
+
|
6
25
|
* *benchmarking*
|
7
26
|
* *colorization by class/method*
|
8
27
|
* *robust argument printer with customizable ellipsis*
|
@@ -13,42 +32,18 @@ Unobtrusive, inheritable-overridable-configurable, drop-in debug logging, that w
|
|
13
32
|
* *Prevents heavy computation of strings with `logger.debug { 'log me' }` block format.*
|
14
33
|
* **so many free ponies** 🎠🐴🎠🐴🎠🐴
|
15
34
|
|
16
|
-
| Project | DebugLogging |
|
17
|
-
|------------------------ | ----------------- |
|
18
|
-
| gem name | debug_logging |
|
19
|
-
| license | [](https://opensource.org/licenses/MIT) |
|
20
|
-
| expert support | [](https://www.codementor.io/peterboling?utm_source=github&utm_medium=button&utm_term=peterboling&utm_campaign=github) |
|
21
|
-
| download rank | [](https://rubygems.org/gems/debug_logging) |
|
22
|
-
| version | [](http://badge.fury.io/rb/debug_logging) |
|
23
|
-
| dependencies | [](https://gemnasium.com/pboling/debug_logging) |
|
24
|
-
| code quality | [](https://codeclimate.com/github/pboling/debug_logging) |
|
25
|
-
| continuous integration | [](https://travis-ci.org/pboling/debug_logging) |
|
26
|
-
| test coverage | [](https://coveralls.io/r/pboling/debug_logging) |
|
27
|
-
| homepage | [https://github.com/pboling/debug_logging][homepage] |
|
28
|
-
| documentation | [http://rdoc.info/github/pboling/debug_logging/frames][documentation] |
|
29
|
-
| live chat | [](https://gitter.im/pboling/debug_logging?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) |
|
30
|
-
| Spread ~♡ⓛⓞⓥⓔ♡~ | [on AngelList][angellist], [on Coderwall][coderwall] |
|
31
|
-
|
32
35
|
## Next Level Magic
|
33
36
|
|
34
|
-
|
35
37
|
Herein you will find:
|
36
38
|
|
37
|
-
* Classes inheriting from Module
|
38
|
-
*
|
39
|
-
*
|
40
|
-
* 100%
|
41
|
-
* 100%
|
42
|
-
* 50% Ruby 2.0+ compatible.
|
43
|
-
* 100% Ruby 2.1+ compatible, and therefore also compatible with JRuby 9000 and later.
|
44
|
-
* 10g Monosodium glutamate.
|
39
|
+
* Classes inheriting from Module
|
40
|
+
* Zero tolerance policy on monkey patching
|
41
|
+
* 100% clean, 0% obtrusive
|
42
|
+
* 100% tested
|
43
|
+
* 100% Ruby 2.3+ compatible
|
45
44
|
|
46
45
|
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.
|
47
46
|
|
48
|
-
NOTE: The instance method logging works on Ruby 2.0+
|
49
|
-
|
50
|
-
NOTE: The class method logging works on Ruby 2.1+
|
51
|
-
|
52
47
|
## Installation
|
53
48
|
|
54
49
|
Add this line to your application's Gemfile:
|
@@ -74,11 +69,11 @@ Crack open the specs for more complex usage examples than the ones below.
|
|
74
69
|
### Without Rails
|
75
70
|
|
76
71
|
It just works. ;)
|
77
|
-
Configuration can go anywhere you want.
|
72
|
+
Configuration can go anywhere you want. Configuration is the same regardless; see below.
|
78
73
|
|
79
74
|
### With Rails
|
80
75
|
|
81
|
-
Recommend creating `config/initializers/debug_logging.rb` with:
|
76
|
+
Recommend creating `config/initializers/debug_logging.rb`, or adding to `config/application.rb` with:
|
82
77
|
|
83
78
|
```ruby
|
84
79
|
# Showing the defaults
|
@@ -207,14 +202,14 @@ dependency on this gem using the [Pessimistic Version Constraint](http://docs.ru
|
|
207
202
|
For example:
|
208
203
|
|
209
204
|
```ruby
|
210
|
-
spec.add_dependency 'debug_logging', '~>
|
205
|
+
spec.add_dependency 'debug_logging', '~> 2.0'
|
211
206
|
```
|
212
207
|
|
213
|
-
## License
|
208
|
+
## License [](https://opensource.org/licenses/MIT)
|
214
209
|
|
215
210
|
MIT License
|
216
211
|
|
217
|
-
Copyright (c) 2017 [Peter Boling][peterboling] of [RailsBling.com][railsbling]
|
212
|
+
Copyright (c) 2017 - 2020 [Peter Boling][peterboling] of [RailsBling.com][railsbling]
|
218
213
|
|
219
214
|
Permission is hereby granted, free of charge, to any person obtaining
|
220
215
|
a copy of this software and associated documentation files (the
|
@@ -243,3 +238,4 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
243
238
|
[angellist]: https://angel.co/peter-boling
|
244
239
|
[documentation]: http://rdoc.info/github/pboling/debug_logging/frames
|
245
240
|
[homepage]: https://github.com/pboling/debug_logging
|
241
|
+
[blogpage]: http://www.railsbling.com/tags/debug_logging/
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
|
-
require
|
4
|
-
require
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'debug_logging'
|
5
6
|
|
6
7
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
8
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +11,5 @@ require "debug_logging"
|
|
10
11
|
# require "pry"
|
11
12
|
# Pry.start
|
12
13
|
|
13
|
-
require
|
14
|
+
require 'irb'
|
14
15
|
IRB.start(__FILE__)
|
data/debug_logging.gemspec
CHANGED
@@ -1,35 +1,38 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
5
|
require 'debug_logging/version'
|
5
6
|
|
6
7
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
8
|
+
spec.name = 'debug_logging'
|
8
9
|
spec.version = DebugLogging::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
10
|
+
spec.authors = ['Peter Boling']
|
11
|
+
spec.email = ['peter.boling@gmail.com']
|
11
12
|
|
12
|
-
spec.summary =
|
13
|
-
spec.description =
|
13
|
+
spec.summary = 'Drop-in debug logging useful when a call stack gets unruly'
|
14
|
+
spec.description = '
|
14
15
|
Unobtrusive debug logging for Ruby. NO LITTERING.
|
15
16
|
Automatically log selected methods and their arguments as they are called at runtime!
|
16
|
-
|
17
|
-
spec.license =
|
18
|
-
spec.homepage =
|
17
|
+
'
|
18
|
+
spec.license = 'MIT'
|
19
|
+
spec.homepage = 'https://github.com/pboling/debug_logging'
|
19
20
|
|
20
21
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
21
22
|
f.match(%r{^(test|spec|features)/})
|
22
23
|
end
|
23
|
-
spec.bindir =
|
24
|
+
spec.bindir = 'exe'
|
24
25
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
|
-
spec.require_paths = [
|
26
|
-
spec.required_ruby_version =
|
26
|
+
spec.require_paths = ['lib']
|
27
|
+
spec.required_ruby_version = '>= 2.3.0' # Uses magic comments
|
27
28
|
|
28
|
-
spec.add_runtime_dependency
|
29
|
-
spec.add_development_dependency
|
30
|
-
spec.add_development_dependency
|
31
|
-
spec.add_development_dependency
|
32
|
-
spec.add_development_dependency
|
33
|
-
spec.add_development_dependency
|
34
|
-
spec.add_development_dependency
|
29
|
+
spec.add_runtime_dependency 'colorize', '>= 0'
|
30
|
+
spec.add_development_dependency 'bundler', '>= 2'
|
31
|
+
spec.add_development_dependency 'byebug', '>= 11'
|
32
|
+
spec.add_development_dependency 'rake', '>= 13'
|
33
|
+
spec.add_development_dependency 'rspec', '>= 3'
|
34
|
+
spec.add_development_dependency 'rspec-pending_for', '>= 0'
|
35
|
+
spec.add_development_dependency 'rubocop', '>= 0'
|
36
|
+
spec.add_development_dependency 'rubocop-rspec', '>= 1'
|
37
|
+
spec.add_development_dependency 'silent_stream', '>= 1'
|
35
38
|
end
|
data/lib/debug_logging.rb
CHANGED
@@ -1,13 +1,15 @@
|
|
1
|
-
|
2
|
-
require "colorized_string"
|
3
|
-
require "digest"
|
1
|
+
# frozen_string_literal: true
|
4
2
|
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
|
9
|
-
require
|
10
|
-
require
|
3
|
+
require 'logger'
|
4
|
+
require 'colorized_string'
|
5
|
+
require 'digest'
|
6
|
+
|
7
|
+
require 'debug_logging/version'
|
8
|
+
require 'debug_logging/configuration'
|
9
|
+
require 'debug_logging/argument_printer'
|
10
|
+
require 'debug_logging/instance_logger_modulizer'
|
11
|
+
require 'debug_logging/instance_logger'
|
12
|
+
require 'debug_logging/class_logger'
|
11
13
|
|
12
14
|
####################
|
13
15
|
# #
|
@@ -58,16 +60,16 @@ require "debug_logging/class_logger"
|
|
58
60
|
module DebugLogging
|
59
61
|
def self.extended(base)
|
60
62
|
base.send(:extend, ArgumentPrinter)
|
61
|
-
base.debug_config_reset(debug_logging_configuration.
|
63
|
+
base.debug_config_reset(Configuration.new(**debug_logging_configuration.to_hash))
|
62
64
|
end
|
63
65
|
|
64
66
|
#### API ####
|
65
|
-
# Not used by this gem internally, but provides an external interface for
|
67
|
+
# Not used by this gem internally, but provides an external interface for
|
66
68
|
# classes to also use this logging tool directly,
|
67
69
|
# with configured options like benchmarking, colors, or leg level.
|
68
70
|
def debug_log(message = nil, config_proxy = nil, &block)
|
69
71
|
# If a, instance-method-level, or class-method-level custom config is not
|
70
|
-
# passed in, then fall back to the class' default config, which is a
|
72
|
+
# passed in, then fall back to the class' default config, which is a
|
71
73
|
# potentially customized copy of the default config for the whole app.
|
72
74
|
config_proxy ||= debug_config
|
73
75
|
config_proxy.log(message, &block)
|
@@ -103,81 +105,115 @@ module DebugLogging
|
|
103
105
|
def debug_config_reset(config = Configuration.new)
|
104
106
|
@debug_logging_configuration = config
|
105
107
|
end
|
108
|
+
|
109
|
+
def debug_enabled
|
110
|
+
@debug_logging_configuration.enabled
|
111
|
+
end
|
112
|
+
|
113
|
+
def debug_enabled=(value)
|
114
|
+
@debug_logging_configuration.enabled = value
|
115
|
+
end
|
116
|
+
|
106
117
|
def debug_logger
|
107
118
|
@debug_logging_configuration.logger
|
108
119
|
end
|
120
|
+
|
109
121
|
def debug_logger=(logger)
|
110
122
|
@debug_logging_configuration.logger = logger
|
111
123
|
end
|
124
|
+
|
112
125
|
def debug_log_level
|
113
126
|
@debug_logging_configuration.log_level
|
114
127
|
end
|
128
|
+
|
115
129
|
def debug_log_level=(log_level)
|
116
130
|
@debug_logging_configuration.log_level = log_level
|
117
131
|
end
|
132
|
+
|
118
133
|
def debug_multiple_last_hashes
|
119
134
|
@debug_logging_configuration.multiple_last_hashes
|
120
135
|
end
|
136
|
+
|
121
137
|
def debug_multiple_last_hashes=(multiple_last_hashes)
|
122
138
|
@debug_logging_configuration.multiple_last_hashes = multiple_last_hashes
|
123
139
|
end
|
140
|
+
|
124
141
|
def debug_last_hash_to_s_proc
|
125
142
|
@debug_logging_configuration.last_hash_to_s_proc
|
126
143
|
end
|
144
|
+
|
127
145
|
def debug_last_hash_to_s_proc=(last_hash_to_s_proc)
|
128
146
|
@debug_logging_configuration.last_hash_to_s_proc = last_hash_to_s_proc
|
129
147
|
end
|
148
|
+
|
130
149
|
def debug_last_hash_max_length
|
131
150
|
@debug_logging_configuration.last_hash_max_length
|
132
151
|
end
|
152
|
+
|
133
153
|
def debug_last_hash_max_length=(last_hash_max_length)
|
134
154
|
@debug_logging_configuration.last_hash_max_length = last_hash_max_length
|
135
155
|
end
|
156
|
+
|
136
157
|
def debug_args_max_length
|
137
158
|
@debug_logging_configuration.args_max_length
|
138
159
|
end
|
160
|
+
|
139
161
|
def debug_args_max_length=(args_max_length)
|
140
162
|
@debug_logging_configuration.args_max_length = args_max_length
|
141
163
|
end
|
164
|
+
|
142
165
|
def debug_instance_benchmarks
|
143
166
|
@debug_logging_configuration.instance_benchmarks
|
144
167
|
end
|
168
|
+
|
145
169
|
def debug_instance_benchmarks=(instance_benchmarks)
|
146
170
|
@debug_logging_configuration.instance_benchmarks = instance_benchmarks
|
147
171
|
end
|
172
|
+
|
148
173
|
def debug_class_benchmarks
|
149
174
|
@debug_logging_configuration.class_benchmarks
|
150
175
|
end
|
176
|
+
|
151
177
|
def debug_class_benchmarks=(class_benchmarks)
|
152
178
|
@debug_logging_configuration.class_benchmarks = class_benchmarks
|
153
179
|
end
|
180
|
+
|
154
181
|
def debug_colorized_chain_for_method
|
155
182
|
@debug_logging_configuration.colorized_chain_for_method
|
156
183
|
end
|
184
|
+
|
157
185
|
def debug_colorized_chain_for_method=(colorized_chain_for_method)
|
158
186
|
@debug_logging_configuration.colorized_chain_for_method = colorized_chain_for_method
|
159
187
|
end
|
188
|
+
|
160
189
|
def debug_colorized_chain_for_class
|
161
190
|
@debug_logging_configuration.colorized_chain_for_class
|
162
191
|
end
|
192
|
+
|
163
193
|
def debug_colorized_chain_for_class=(colorized_chain_for_class)
|
164
194
|
@debug_logging_configuration.colorized_chain_for_class = colorized_chain_for_class
|
165
195
|
end
|
196
|
+
|
166
197
|
def debug_add_invocation_id
|
167
198
|
@debug_logging_configuration.add_invocation_id
|
168
199
|
end
|
200
|
+
|
169
201
|
def debug_add_invocation_id=(add_invocation_id)
|
170
202
|
@debug_logging_configuration.add_invocation_id = add_invocation_id
|
171
203
|
end
|
204
|
+
|
172
205
|
def debug_mark_scope_exit
|
173
206
|
@debug_logging_configuration.mark_scope_exit
|
174
207
|
end
|
208
|
+
|
175
209
|
def debug_mark_scope_exit=(mark_scope_exit)
|
176
210
|
@debug_logging_configuration.mark_scope_exit = mark_scope_exit
|
177
211
|
end
|
212
|
+
|
178
213
|
def debug_ellipsis
|
179
214
|
@debug_logging_configuration.ellipsis
|
180
215
|
end
|
216
|
+
|
181
217
|
def debug_ellipsis=(ellipsis)
|
182
218
|
@debug_logging_configuration.ellipsis = ellipsis
|
183
219
|
end
|
@@ -1,21 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module DebugLogging
|
2
4
|
module ArgumentPrinter
|
3
5
|
def debug_benchmark_to_s(tms: nil)
|
4
|
-
"completed in #{
|
6
|
+
"completed in #{format('%f', tms.real)}s (#{format('%f', tms.total)}s CPU)"
|
5
7
|
end
|
8
|
+
|
6
9
|
def debug_invocation_id_to_s(args: nil, config_proxy: nil)
|
7
10
|
if config_proxy.debug_add_invocation_id
|
8
|
-
invocation = " ~#{args.object_id}@#{(Time.now.to_f.to_s % '%#-21a')[4
|
11
|
+
invocation = " ~#{args.object_id}@#{(Time.now.to_f.to_s % '%#-21a')[4..-4]}~"
|
9
12
|
case config_proxy.debug_add_invocation_id
|
10
|
-
when true
|
13
|
+
when true
|
11
14
|
invocation
|
12
15
|
else
|
13
16
|
config_proxy.debug_add_invocation_id.call(ColorizedString[invocation])
|
14
17
|
end
|
15
18
|
else
|
16
|
-
|
19
|
+
''
|
17
20
|
end
|
18
21
|
end
|
22
|
+
|
19
23
|
def debug_invocation_to_s(klass: nil, separator: nil, method_to_log: nil, config_proxy: nil)
|
20
24
|
klass_string = if config_proxy.debug_colorized_chain_for_class
|
21
25
|
config_proxy.debug_colorized_chain_for_class.call(ColorizedString[klass.to_s])
|
@@ -29,50 +33,55 @@ module DebugLogging
|
|
29
33
|
end
|
30
34
|
"#{klass_string}#{separator}#{method_string}"
|
31
35
|
end
|
32
|
-
|
33
|
-
|
36
|
+
|
37
|
+
def debug_signature_to_s(args: nil, config_proxy: nil) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
38
|
+
printed_args = ''
|
39
|
+
|
34
40
|
add_args_ellipsis = false
|
35
41
|
if config_proxy.debug_last_hash_to_s_proc && args[-1].is_a?(Hash)
|
42
|
+
add_last_hash_ellipsis = false
|
36
43
|
if args.length > 1
|
37
|
-
add_last_hash_ellipsis = false
|
38
44
|
if config_proxy.debug_multiple_last_hashes
|
39
45
|
last_hash_args, other_args = args.partition do |arg|
|
40
|
-
|
41
|
-
|
42
|
-
other_args_string = other_args.map(&:inspect).join(
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
+
arg.is_a?(Hash)
|
47
|
+
end
|
48
|
+
other_args_string = other_args.map(&:inspect).join(', ')[0..(config_proxy.debug_args_max_length)]
|
49
|
+
# On the debug_multiple_last_hashes truthy branch we don't print the ellipsis after regular args
|
50
|
+
# because it will go instead after the last hash (if needed)
|
51
|
+
# ...join(", ").tap {|x| _add_args_ellipsis = x.length > config_proxy.debug_args_max_length}
|
46
52
|
last_hash_args_string = last_hash_args.map do |arg|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
53
|
+
arr = []
|
54
|
+
arr << config_proxy.debug_last_hash_to_s_proc.call(arg).to_s
|
55
|
+
.tap do |x|
|
56
|
+
add_last_hash_ellipsis = x.length > config_proxy.debug_last_hash_max_length
|
57
|
+
end
|
58
|
+
if add_last_hash_ellipsis
|
59
|
+
arr[-1] = arr[-1][0..(config_proxy.debug_last_hash_max_length)]
|
60
|
+
arr << config_proxy.debug_ellipsis
|
61
|
+
end
|
62
|
+
arr
|
63
|
+
end.flatten.join(', ')
|
64
|
+
printed_args += other_args_string if other_args_string
|
65
|
+
printed_args += ', ' if !other_args_string.empty? && !last_hash_args_string.empty?
|
66
|
+
printed_args += last_hash_args_string if last_hash_args_string && !last_hash_args_string.empty?
|
58
67
|
else
|
59
|
-
printed_args
|
60
|
-
printed_args
|
61
|
-
printed_args
|
62
|
-
printed_args
|
68
|
+
printed_args += args[0..-2].map(&:inspect).join(', ').tap { |x| add_args_ellipsis = x.length > config_proxy.debug_args_max_length }[0..(config_proxy.debug_args_max_length)]
|
69
|
+
printed_args += config_proxy.debug_ellipsis if add_args_ellipsis
|
70
|
+
printed_args += ", #{config_proxy.debug_last_hash_to_s_proc.call(args[-1]).tap { |x| add_last_hash_ellipsis = x.length > config_proxy.debug_last_hash_max_length }[0..(config_proxy.debug_last_hash_max_length)]}"
|
71
|
+
printed_args += config_proxy.debug_ellipsis if add_last_hash_ellipsis
|
63
72
|
end
|
64
73
|
else
|
65
|
-
printed_args
|
66
|
-
printed_args
|
74
|
+
printed_args += String(config_proxy.debug_last_hash_to_s_proc.call(args[0])).tap { |x| add_last_hash_ellipsis = x.length > config_proxy.debug_last_hash_max_length }[0..(config_proxy.debug_last_hash_max_length)]
|
75
|
+
printed_args += config_proxy.debug_ellipsis if add_last_hash_ellipsis
|
67
76
|
end
|
68
77
|
else
|
69
78
|
if args.length == 1 && args[0].is_a?(Hash)
|
70
79
|
# handle double splat
|
71
|
-
printed_args
|
80
|
+
printed_args += ("**#{args.map(&:inspect).join(', ').tap { |x| add_args_ellipsis = x.length > config_proxy.debug_args_max_length }}")[0..(config_proxy.debug_args_max_length)]
|
72
81
|
else
|
73
|
-
printed_args
|
82
|
+
printed_args += args.map(&:inspect).join(', ').tap { |x| add_args_ellipsis = x.length > config_proxy.debug_args_max_length}[0..(config_proxy.debug_args_max_length)]
|
74
83
|
end
|
75
|
-
printed_args
|
84
|
+
printed_args += config_proxy.debug_ellipsis if add_args_ellipsis
|
76
85
|
end
|
77
86
|
"(#{printed_args})"
|
78
87
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module DebugLogging
|
2
4
|
module ClassLogger
|
3
5
|
def logged(*methods_to_log)
|
@@ -19,7 +21,7 @@ module DebugLogging
|
|
19
21
|
proxy
|
20
22
|
else
|
21
23
|
proxy = if opts
|
22
|
-
Configuration.new(**
|
24
|
+
Configuration.new(**debug_config.to_hash.merge(opts))
|
23
25
|
else
|
24
26
|
debug_config
|
25
27
|
end
|
@@ -31,7 +33,7 @@ module DebugLogging
|
|
31
33
|
log_prefix = nil
|
32
34
|
invocation_id = nil
|
33
35
|
config_proxy.log do
|
34
|
-
log_prefix = debug_invocation_to_s(klass: to_s, separator:
|
36
|
+
log_prefix = debug_invocation_to_s(klass: to_s, separator: '.', method_to_log: method_to_log, config_proxy: config_proxy)
|
35
37
|
invocation_id = debug_invocation_id_to_s(args: args, config_proxy: config_proxy)
|
36
38
|
signature = debug_signature_to_s(args: args, config_proxy: config_proxy)
|
37
39
|
"#{log_prefix}#{signature}#{invocation_id}"
|
@@ -1,21 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module DebugLogging
|
2
4
|
class Configuration
|
3
|
-
DEFAULT_ELLIPSIS =
|
5
|
+
DEFAULT_ELLIPSIS = ' ✂️ …'
|
6
|
+
# For reference, log levels as integers mapped to symbols:
|
4
7
|
# LEVELS = { 0 => :debug, 1 => :info, 2 => :warn, 3 => :error, 4 => :fatal, 5 => :unknown }
|
5
|
-
attr_accessor :
|
6
|
-
attr_accessor :log_level
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
attr_accessor :args_max_length
|
11
|
-
attr_accessor :instance_benchmarks
|
12
|
-
attr_accessor :class_benchmarks
|
13
|
-
attr_accessor :colorized_chain_for_method
|
14
|
-
attr_accessor :colorized_chain_for_class
|
15
|
-
attr_accessor :add_invocation_id
|
16
|
-
attr_accessor :ellipsis
|
17
|
-
attr_accessor :mark_scope_exit
|
18
|
-
attr_reader :methods_to_log
|
8
|
+
attr_accessor :enabled
|
9
|
+
attr_accessor :logger, :log_level, :multiple_last_hashes, :last_hash_to_s_proc, :last_hash_max_length,
|
10
|
+
:args_max_length, :colorized_chain_for_method, :colorized_chain_for_class, :add_invocation_id,
|
11
|
+
:ellipsis, :mark_scope_exit
|
12
|
+
attr_reader :instance_benchmarks, :class_benchmarks, :methods_to_log
|
19
13
|
# alias the readers to the debug_* prefix so an instance of this class
|
20
14
|
# can have the same API granted by `extend DebugLogging`
|
21
15
|
#
|
@@ -34,20 +28,21 @@ module DebugLogging
|
|
34
28
|
# }
|
35
29
|
# )
|
36
30
|
#
|
37
|
-
alias
|
38
|
-
alias
|
39
|
-
alias
|
40
|
-
alias
|
41
|
-
alias
|
42
|
-
alias
|
43
|
-
alias
|
44
|
-
alias
|
45
|
-
alias
|
46
|
-
alias
|
47
|
-
alias
|
48
|
-
alias
|
49
|
-
alias
|
50
|
-
|
31
|
+
alias debug_enabled enabled
|
32
|
+
alias debug_logger logger
|
33
|
+
alias debug_log_level log_level
|
34
|
+
alias debug_multiple_last_hashes multiple_last_hashes
|
35
|
+
alias debug_last_hash_to_s_proc last_hash_to_s_proc
|
36
|
+
alias debug_last_hash_max_length last_hash_max_length
|
37
|
+
alias debug_args_max_length args_max_length
|
38
|
+
alias debug_instance_benchmarks instance_benchmarks
|
39
|
+
alias debug_class_benchmarks class_benchmarks
|
40
|
+
alias debug_colorized_chain_for_method colorized_chain_for_method
|
41
|
+
alias debug_colorized_chain_for_class colorized_chain_for_class
|
42
|
+
alias debug_add_invocation_id add_invocation_id
|
43
|
+
alias debug_ellipsis ellipsis
|
44
|
+
alias debug_mark_scope_exit mark_scope_exit
|
45
|
+
|
51
46
|
class << self
|
52
47
|
def config_pointer(type, method_to_log)
|
53
48
|
# Methods names that do not match the following regex can't be part of an ivar name
|
@@ -57,7 +52,8 @@ module DebugLogging
|
|
57
52
|
end
|
58
53
|
end
|
59
54
|
def initialize(**options)
|
60
|
-
@
|
55
|
+
@enabled = options.key?(:enabled) ? options[:enabled] : true
|
56
|
+
@logger = options.key?(:logger) ? options[:logger] : Logger.new($stdout)
|
61
57
|
@log_level = options.key?(:log_level) ? options[:log_level] : :debug
|
62
58
|
@multiple_last_hashes = options.key?(:multiple_last_hashes) ? options[:multiple_last_hashes] : false
|
63
59
|
@last_hash_to_s_proc = options.key?(:last_hash_to_s_proc) ? options[:last_hash_to_s_proc] : nil
|
@@ -72,50 +68,64 @@ module DebugLogging
|
|
72
68
|
@mark_scope_exit = options.key?(:mark_scope_exit) ? options[:mark_scope_exit] : false
|
73
69
|
@methods_to_log = []
|
74
70
|
end
|
71
|
+
|
75
72
|
def log(message = nil, &block)
|
73
|
+
return unless enabled
|
76
74
|
return unless logger
|
75
|
+
|
77
76
|
if block_given?
|
78
77
|
logger.send(log_level, &block)
|
79
78
|
else
|
80
79
|
logger.send(log_level, message)
|
81
80
|
end
|
82
81
|
end
|
82
|
+
|
83
83
|
def loggable?
|
84
84
|
return @loggable if defined?(@loggable)
|
85
|
+
|
85
86
|
@loggable = logger.send("#{log_level}?")
|
86
87
|
end
|
88
|
+
|
87
89
|
def benchmarkable_for?(benchmarks)
|
88
90
|
return @benchmarkable if defined?(@benchmarkable)
|
89
|
-
|
91
|
+
|
92
|
+
@benchmarkable = loggable? && send(benchmarks)
|
90
93
|
end
|
94
|
+
|
91
95
|
def exit_scope_markable?
|
92
96
|
return @exit_scope_markable if defined?(@exit_scope_markable)
|
97
|
+
|
93
98
|
@exit_scope_markable = loggable? && mark_scope_exit
|
94
99
|
end
|
100
|
+
|
95
101
|
def instance_benchmarks=(instance_benchmarks)
|
96
|
-
require
|
102
|
+
require 'benchmark' if instance_benchmarks
|
97
103
|
@instance_benchmarks = instance_benchmarks
|
98
104
|
end
|
105
|
+
|
99
106
|
def class_benchmarks=(class_benchmarks)
|
100
|
-
require
|
107
|
+
require 'benchmark' if class_benchmarks
|
101
108
|
@class_benchmarks = class_benchmarks
|
102
109
|
end
|
110
|
+
|
103
111
|
def to_hash
|
104
112
|
{
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
113
|
+
logger: logger,
|
114
|
+
log_level: log_level,
|
115
|
+
multiple_last_hashes: multiple_last_hashes,
|
116
|
+
last_hash_to_s_proc: last_hash_to_s_proc,
|
117
|
+
last_hash_max_length: last_hash_max_length,
|
118
|
+
args_max_length: args_max_length,
|
119
|
+
instance_benchmarks: instance_benchmarks,
|
120
|
+
class_benchmarks: class_benchmarks,
|
121
|
+
colorized_chain_for_method: colorized_chain_for_method,
|
122
|
+
colorized_chain_for_class: colorized_chain_for_class,
|
123
|
+
add_invocation_id: add_invocation_id,
|
124
|
+
ellipsis: ellipsis,
|
125
|
+
mark_scope_exit: mark_scope_exit
|
117
126
|
}
|
118
127
|
end
|
128
|
+
|
119
129
|
def register(method_lo_log)
|
120
130
|
@methods_to_log << method_lo_log
|
121
131
|
end
|
@@ -1,11 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module DebugLogging
|
2
4
|
class InstanceLogger < Module
|
3
5
|
def initialize(i_methods: nil, config: nil)
|
6
|
+
super()
|
4
7
|
@config = config
|
5
8
|
@instance_methods_to_log = Array(i_methods) if i_methods
|
6
9
|
end
|
10
|
+
|
7
11
|
def included(base)
|
8
12
|
return unless @instance_methods_to_log
|
13
|
+
|
9
14
|
base.send(:include, ArgumentPrinter)
|
10
15
|
instance_method_logger = DebugLogging::InstanceLoggerModulizer.to_mod(methods_to_log: @instance_methods_to_log, config: @config)
|
11
16
|
base.send(:prepend, instance_method_logger)
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module DebugLogging
|
2
4
|
module InstanceLoggerModulizer
|
3
5
|
def self.to_mod(methods_to_log: nil, config: nil)
|
@@ -10,7 +12,7 @@ module DebugLogging
|
|
10
12
|
proxy
|
11
13
|
else
|
12
14
|
proxy = if config
|
13
|
-
Configuration.new(**
|
15
|
+
Configuration.new(**self.class.debug_config.to_hash.merge(config))
|
14
16
|
else
|
15
17
|
self.class.debug_config
|
16
18
|
end
|
@@ -18,7 +20,7 @@ module DebugLogging
|
|
18
20
|
instance_variable_set(DebugLogging::Configuration.config_pointer('i', method_to_log), proxy)
|
19
21
|
proxy
|
20
22
|
end
|
21
|
-
log_prefix = self.class.debug_invocation_to_s(klass: self.class.to_s, separator:
|
23
|
+
log_prefix = self.class.debug_invocation_to_s(klass: self.class.to_s, separator: '#', method_to_log: method_to_log, config_proxy: config_proxy)
|
22
24
|
invocation_id = self.class.debug_invocation_id_to_s(args: args, config_proxy: config_proxy)
|
23
25
|
config_proxy.log do
|
24
26
|
signature = self.class.debug_signature_to_s(args: args, config_proxy: config_proxy)
|
data/lib/simple_debug_logging.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Simpler version of what the sibling DebugLogging library does. Included as a bauble.
|
2
4
|
#
|
3
5
|
############# THIS IS A BAUBLE
|
4
6
|
############# FOR EXAMINING SEVERAL OF THE WONDERS OF RUBY
|
5
7
|
############# TO ACCOMPLISH SOMETHING PRACTICAL
|
6
|
-
############# For a more robust implementation use the gem debug_logging itself,
|
8
|
+
############# For a more robust implementation use the gem debug_logging itself,
|
7
9
|
############# which makes use of these same principles.
|
8
10
|
#
|
9
11
|
# Automatically log Class.method(arguments) as they are called at runtime (instance or singleton)!
|
@@ -39,8 +41,10 @@ require 'benchmark'
|
|
39
41
|
|
40
42
|
class SimpleDebugLogging < Module
|
41
43
|
def initialize(i_methods: nil)
|
44
|
+
super()
|
42
45
|
@instance_methods_to_log = Array(i_methods) if i_methods
|
43
46
|
end
|
47
|
+
|
44
48
|
def included(base)
|
45
49
|
instance_method_logger = InstanceMethodLoggerModulizer.to_mod(@instance_methods_to_log)
|
46
50
|
base.send(:prepend, instance_method_logger)
|
@@ -54,7 +58,7 @@ class SimpleDebugLogging < Module
|
|
54
58
|
define_method(method_to_log.to_sym) do |*args|
|
55
59
|
method_return_value = nil
|
56
60
|
invocation_id = " ~#{args.object_id}@#{Time.now.to_i}~" if args
|
57
|
-
puts "#{self}.#{method_to_log}(#{args.map
|
61
|
+
puts "#{self}.#{method_to_log}(#{args.map(&:inspect).join(', ')})#{invocation_id}"
|
58
62
|
elapsed = Benchmark.realtime do
|
59
63
|
method_return_value = original_method.call(*args)
|
60
64
|
end
|
@@ -72,7 +76,7 @@ class SimpleDebugLogging < Module
|
|
72
76
|
define_method(method_to_log.to_sym) do |*args, &block|
|
73
77
|
method_return_value = nil
|
74
78
|
invocation_id = " ~#{args.object_id}@#{Time.now.to_i}~" if args
|
75
|
-
puts "#{self.class}##{method_to_log}(#{args.map
|
79
|
+
puts "#{self.class}##{method_to_log}(#{args.map(&:inspect).join(', ')})#{invocation_id}"
|
76
80
|
elapsed = Benchmark.realtime do
|
77
81
|
method_return_value = super(*args, &block)
|
78
82
|
end
|
metadata
CHANGED
@@ -1,113 +1,141 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: debug_logging
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Boling
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-10-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0
|
19
|
+
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '2'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '2'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: byebug
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '11'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '11'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '13'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '13'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '3'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '3'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name: rspec
|
84
|
+
name: rspec-pending_for
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
86
100
|
requirements:
|
87
|
-
- - "
|
101
|
+
- - ">="
|
88
102
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
103
|
+
version: '0'
|
90
104
|
type: :development
|
91
105
|
prerelease: false
|
92
106
|
version_requirements: !ruby/object:Gem::Requirement
|
93
107
|
requirements:
|
94
|
-
- - "
|
108
|
+
- - ">="
|
95
109
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
110
|
+
version: '0'
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
112
|
+
name: rubocop-rspec
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
100
114
|
requirements:
|
101
|
-
- - "
|
115
|
+
- - ">="
|
102
116
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
117
|
+
version: '1'
|
104
118
|
type: :development
|
105
119
|
prerelease: false
|
106
120
|
version_requirements: !ruby/object:Gem::Requirement
|
107
121
|
requirements:
|
108
|
-
- - "
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '1'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: silent_stream
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '1'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
109
137
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
138
|
+
version: '1'
|
111
139
|
description: |2
|
112
140
|
|
113
141
|
Unobtrusive debug logging for Ruby. NO LITTERING.
|
@@ -121,6 +149,8 @@ files:
|
|
121
149
|
- ".coveralls.yml"
|
122
150
|
- ".gitignore"
|
123
151
|
- ".rspec"
|
152
|
+
- ".rubocop.yml"
|
153
|
+
- ".rubocop_todo.yml"
|
124
154
|
- ".travis.yml"
|
125
155
|
- Gemfile
|
126
156
|
- README.md
|
@@ -148,15 +178,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
148
178
|
requirements:
|
149
179
|
- - ">="
|
150
180
|
- !ruby/object:Gem::Version
|
151
|
-
version: 2.
|
181
|
+
version: 2.3.0
|
152
182
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
153
183
|
requirements:
|
154
184
|
- - ">="
|
155
185
|
- !ruby/object:Gem::Version
|
156
186
|
version: '0'
|
157
187
|
requirements: []
|
158
|
-
|
159
|
-
rubygems_version: 2.6.12
|
188
|
+
rubygems_version: 3.1.4
|
160
189
|
signing_key:
|
161
190
|
specification_version: 4
|
162
191
|
summary: Drop-in debug logging useful when a call stack gets unruly
|