Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release/v4.0.2 #127

Merged
merged 17 commits into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export K_SOUP_COV_MIN_HARD=true # Means you want the build to fail if the covera
# Available formats are html, xml, rcov, lcov, json, tty
export K_SOUP_COV_MULTI_FORMATTERS="html,tty" # What coverage output formats do you want?
export MAX_ROWS=5 # Setting for simplecov-console gem for tty output, limits to the worst N rows of bad coverage
export DEBUG=true # Enable to load byebug
335 changes: 147 additions & 188 deletions .rubocop_gradual.lock

Large diffs are not rendered by default.

17 changes: 16 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
### Removed

## [4.0.2] ([tag][4.0.2t]) - 2024-05-12
### Added
- More documentation
### Changed
- DRY logic for `DebugLogging::ClassLogger` & `DebugLogging::InstanceLogger` via `LambDart`
- Refactored test suite; increased test coverage to 97%
- Refactored ActiveSupport::Notification integration (DRY)
### Fixed
- Add undeclared runtime dependency `version_gem`
- `DebugLogging::Hooks` integration via `extend`
- `DebugLogging::ClassNotifier` support for method signatures with kwargs
- `error_handler_proc` support for method signatures with kwargs

## [4.0.1] ([tag][4.0.1t]) - 2024-03-01
### Added
- Support for all Numeric types to be used as monotonic timestamps for ActiveSupport::Notifications
Expand Down Expand Up @@ -105,7 +118,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [0.1.0] ([tag][0.1.0t]) - 2017-03-25
- Initial release

[Unreleased]: https://gitlab.com/kettle-rb/kettle-soup-cover/-/compare/v4.0.1...HEAD
[Unreleased]: https://gitlab.com/kettle-rb/kettle-soup-cover/-/compare/v4.0.2...HEAD
[4.0.2t]: https://gitlab.com/pboling/debug_logging/-/tags/v4.0.2
[4.0.2]: https://gitlab.com/kettle-rb/kettle-soup-cover/-/compare/v4.0.1...v4.0.2
[4.0.1t]: https://gitlab.com/pboling/debug_logging/-/tags/v4.0.1
[4.0.1]: https://gitlab.com/kettle-rb/kettle-soup-cover/-/compare/v4.0.0...v4.0.1
[4.0.0t]: https://gitlab.com/pboling/debug_logging/-/tags/v4.0.0
Expand Down
58 changes: 32 additions & 26 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
PATH
remote: .
specs:
debug_logging (4.0.1)
debug_logging (4.0.2)
colorize
version_gem (~> 1.1, >= 1.1.4)

GEM
remote: https://rubygems.org/
Expand All @@ -19,9 +20,9 @@ GEM
tzinfo (~> 2.0)
ansi (1.5.0)
ast (2.4.2)
backports (3.24.1)
backports (3.25.0)
base64 (0.2.0)
bigdecimal (3.1.6)
bigdecimal (3.1.8)
byebug (11.1.3)
colorize (1.1.0)
concurrent-ruby (1.2.3)
Expand All @@ -30,9 +31,9 @@ GEM
diffy (3.4.2)
docile (1.4.0)
drb (2.2.1)
i18n (1.14.1)
i18n (1.14.5)
concurrent-ruby (~> 1.0)
json (2.7.1)
json (2.7.2)
kettle-soup-cover (1.0.2)
simplecov (~> 0.22)
simplecov-cobertura (~> 2.1)
Expand All @@ -46,16 +47,16 @@ GEM
rexml
language_server-protocol (3.17.0.3)
lint_roller (1.1.0)
minitest (5.22.2)
minitest (5.22.3)
mutex_m (0.2.0)
parallel (1.24.0)
parser (3.3.0.5)
parser (3.3.1.0)
ast (~> 2.4.1)
racc
racc (1.7.3)
rainbow (3.1.1)
rake (13.1.0)
regexp_parser (2.9.0)
rake (13.2.1)
regexp_parser (2.9.1)
rexml (3.2.6)
rspec (3.13.0)
rspec-core (~> 3.13.0)
Expand All @@ -67,7 +68,7 @@ GEM
rspec-expectations (3.13.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-mocks (3.13.0)
rspec-mocks (3.13.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-pending_for (0.1.16)
Expand All @@ -77,19 +78,19 @@ GEM
rspec-support (3.13.1)
rspec_junit_formatter (0.6.0)
rspec-core (>= 2, < 4, != 2.12.0)
rubocop (1.61.0)
rubocop (1.62.1)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.30.0, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.31.1)
parser (>= 3.3.0.4)
rubocop-ast (1.31.3)
parser (>= 3.3.1.0)
rubocop-capybara (2.20.0)
rubocop (~> 1.41)
rubocop-factory_bot (2.25.1)
Expand All @@ -113,10 +114,13 @@ GEM
rubocop-ast (>= 1.30.0, < 2.0)
rubocop-rake (0.6.0)
rubocop (~> 1.0)
rubocop-rspec (2.27.0)
rubocop-rspec (2.29.2)
rubocop (~> 1.40)
rubocop-capybara (~> 2.17)
rubocop-factory_bot (~> 2.22)
rubocop-rspec_rails (~> 2.28)
rubocop-rspec_rails (2.28.3)
rubocop (~> 1.40)
rubocop-ruby3_1 (2.0.6)
rubocop-gradual (~> 0.3, >= 0.3.1)
rubocop-md (~> 1.2)
Expand All @@ -130,9 +134,9 @@ GEM
rubocop-thread_safety (0.5.1)
rubocop (>= 0.90.0)
ruby-progressbar (1.13.0)
ruby_engine (2.0.0)
ruby_engine (2.0.3)
ruby_version (1.0.3)
silent_stream (1.0.6)
silent_stream (1.0.8)
simplecov (0.22.0)
docile (~> 1.1)
simplecov-html (~> 0.11)
Expand All @@ -149,10 +153,10 @@ GEM
simplecov-rcov (0.3.7)
simplecov (>= 0.4.1)
simplecov_json_formatter (0.1.4)
standard (1.34.0)
standard (1.35.1)
language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.0)
rubocop (~> 1.60)
rubocop (~> 1.62.0)
standard-custom (~> 1.0.0)
standard-performance (~> 1.3)
standard-custom (1.0.2)
Expand All @@ -161,17 +165,18 @@ GEM
standard-performance (1.3.1)
lint_roller (~> 1.1)
rubocop-performance (~> 1.20.2)
standard-rubocop-lts (1.0.9)
standard (>= 1.31.1, < 2)
standard-custom (>= 1.0.1, < 2)
standard-performance (>= 1.2, < 2)
version_gem (>= 1.1.3, < 4)
standard-rubocop-lts (1.0.10)
rspec-block_is_expected (~> 1.0, >= 1.0.5)
standard (>= 1.35.1, < 2)
standard-custom (>= 1.0.2, < 2)
standard-performance (>= 1.3.1, < 2)
version_gem (>= 1.1.4, < 3)
terminal-table (3.0.2)
unicode-display_width (>= 1.1.1, < 3)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.5.0)
version_gem (1.1.3)
version_gem (1.1.4)
yard (0.9.36)
yard-junk (0.0.9)
backports (>= 3.18)
Expand All @@ -187,7 +192,7 @@ DEPENDENCIES
debug_logging!
kettle-soup-cover (~> 1.0, >= 1.0.2)
kramdown (~> 2.4)
rake (>= 13)
rake (>= 13.2.1)
rspec (>= 3)
rspec-block_is_expected (~> 1.0, >= 1.0.5)
rspec-pending_for
Expand All @@ -196,6 +201,7 @@ DEPENDENCIES
rubocop-packaging (~> 0.5, >= 0.5.2)
rubocop-rspec (~> 2.25)
silent_stream (>= 1)
standard-rubocop-lts (~> 1.0, >= 1.0.10)
yard (~> 0.9, >= 0.9.34)
yard-junk (~> 0.0)

Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,15 @@ Supports `ActiveSupport::Notifications` (thanks [@jgillson](https://github.com/j
* *All configuration is inheritable to, and overridable by, child classes, since v3.1.3*
* *[Class finalization hook](https://stackoverflow.com/a/34559282) (optional: `require 'debug_logging/finalize'` and `extend DebugLogging::Finalize`), since v3.1.3*
* *Error handling hooks you can use to log problems when they happen, since v3.1.7*
* *Fixed: Works with benchmarking options since v4.0.2*
* **so many free ponies** 🎠🐴🎠🐴🎠🐴

## Next Level Magic

Herein you will find:

* ~~Classes inheriting from Module~~ Refactored to use standard Modules and `prepend`!
* Zero tolerance policy on monkey patching
* Zero tolerance policy on global monkey patching
* When the gem is loaded there are no monkey patches.
* Rather, your own classes/methods get "patched" and "hooked" as you configure them.
* 100% clean, 0% obtrusive
Expand Down Expand Up @@ -166,7 +167,7 @@ DebugLogging.configuration.ellipsis = " ✂️ …".freeze
DebugLogging.configuration.mark_scope_exit = true # Only has an effect if benchmarking is off, since benchmarking always marks the scope exit
DebugLogging.configuration.add_payload = false # or a proc which will be called to print the payload
DebugLogging.configuration.payload_max_length = 1000
DebugLogging.configuration.error_handler_proc = nil # e.g. ->(error, config, obj, method_name, args) { config.log { "#{error.class}: #{error.message} in #{method_name}\nargs: #{args.inspect}" } }
DebugLogging.configuration.error_handler_proc = nil # e.g. ->(error, config, obj, method_name, *args, **kwargs) { config.log { "#{error.class}: #{error.message} in #{method_name}\nargs: #{args.inspect}" } }
```

If you prefer to use the block style:
Expand All @@ -192,7 +193,7 @@ DebugLogging.configure do |config|
config.mark_scope_exit = true # Only has an effect if benchmarking is off, since benchmarking always marks the scope exit
config.add_payload = false # or a proc which will be called to print the payload
config.payload_max_length = 1000
config.error_handler_proc = nil # e.g. ->(error, config, obj, method_name, args) { config.log { "#{error.class}: #{error.message} in #{method_name}\nargs: #{args.inspect}" } }
config.error_handler_proc = nil # e.g. ->(error, config, obj, method_name, *args, **kwargs) { config.log { "#{error.class}: #{error.message} in #{method_name}\nargs: #{args.inspect}" } }
end
```

Expand Down Expand Up @@ -264,6 +265,7 @@ class Car
logged :dealer_options, {
something: "here", # <= will be logged, and available to last_hash_to_s_proc
multiple_last_hashes: true, # <= Overrides config
error_handler_proc: nil, # NOTE: if you define the error_handler_proc inside a class like this you can use self inside the proc to refer to the class the method was called on!
}
def self.will_not_be_logged
false
Expand Down Expand Up @@ -314,7 +316,7 @@ class Car
mark_scope_exit: false,
add_payload: true, # Can also be a proc returning a string, which will be called when printing the payload
payload_max_length: 1_000,
error_handler_proc: nil,
error_handler_proc: nil, # NOTE: if you define the error_handler_proc inside a class like this you can use self inside the proc to refer to the instance of the class the method was called on!
time_formatter_proc: DebugLogging::Constants::DEFAULT_TIME_FORMATTER,
add_timestamp: false,
instance_benchmarks: false,
Expand Down
11 changes: 6 additions & 5 deletions debug_logging.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ Gem::Specification.new do |spec|
Unobtrusive debug logging for Ruby. NO LITTERING.
Automatically log selected methods and their arguments as they are called at runtime!
'
spec.homepage = "https://github.com/pboling/debug_logging"
spec.license = "MIT"
spec.required_ruby_version = ">= 3.1"

spec.homepage = "https://github.com/pboling/debug_logging"
spec.metadata["homepage_uri"] = spec.homepage
spec.metadata["source_code_uri"] = "https://github.com/pboling/debug_logging/tree/v#{spec.version}"
spec.metadata["changelog_uri"] = "https://github.com/pboling/debug_logging/blob/v#{spec.version}/CHANGELOG.md"
Expand All @@ -33,7 +33,6 @@ Automatically log selected methods and their arguments as they are called at run
spec.metadata["rubygems_mfa_required"] = "true"

# Specify which files should be added to the gem when it is released.
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
spec.files = Dir[
"lib/**/*.rb",
"CHANGELOG.md",
Expand All @@ -53,12 +52,13 @@ Automatically log selected methods and their arguments as they are called at run

spec.add_dependency("colorize", ">= 0")

# Utilities
spec.add_dependency("version_gem", "~> 1.1", ">= 1.1.4")
spec.add_development_dependency("rake", ">= 13.2.1")

# Optional
spec.add_development_dependency("activesupport", ">= 5.2.4.4")

# Utilities
spec.add_development_dependency("rake", ">= 13")

# Code Coverage
# CodeCov + GitHub setup is not via gems: https://github.com/marketplace/actions/codecov
spec.add_development_dependency("kettle-soup-cover", "~> 1.0", ">= 1.0.2")
Expand All @@ -72,6 +72,7 @@ Automatically log selected methods and their arguments as they are called at run
spec.add_development_dependency("rubocop-lts", "~> 22.1", ">= 22.1.3")
spec.add_development_dependency("rubocop-packaging", "~> 0.5", ">= 0.5.2")
spec.add_development_dependency("rubocop-rspec", "~> 2.25")
spec.add_development_dependency("standard-rubocop-lts", "~> 1.0", ">= 1.0.10")

# Testing
spec.add_development_dependency("rspec", ">= 3")
Expand Down
9 changes: 2 additions & 7 deletions lib/debug_logging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,12 @@
require "debug_logging/finalize"
require "debug_logging/argument_printer"
require "debug_logging/hooks"
require "debug_logging/lamb_dart"
require "debug_logging/lamb_dartable"
require "debug_logging/instance_logger_modulizer"
require "debug_logging/instance_logger"
require "debug_logging/class_logger"

####################
# #
# 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.
# NOTE: The instance method manner works on Ruby 2.0+
# NOTE: The class method manner works on Ruby 2.1+
# #
####################
# #
# USAGE (see specs)#
Expand Down
12 changes: 6 additions & 6 deletions lib/debug_logging/argument_printer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def debug_event_time_to_s(time_or_monotonic)
DebugLogging::Constants::EVENT_TIME_FORMATTER.call(time)
end

def debug_invocation_to_s(klass: nil, separator: nil, method_to_log: nil, config_proxy: nil)
def debug_invocation_to_s(klass: nil, separator: nil, decorated_method: nil, config_proxy: nil)
return "" unless config_proxy

klass_string = if config_proxy.debug_colorized_chain_for_class
Expand All @@ -55,9 +55,9 @@ def debug_invocation_to_s(klass: nil, separator: nil, method_to_log: nil, config
klass.to_s
end
method_string = if config_proxy.debug_colorized_chain_for_method
config_proxy.debug_colorized_chain_for_method.call(ColorizedString[method_to_log.to_s])
config_proxy.debug_colorized_chain_for_method.call(ColorizedString[decorated_method.to_s])
else
method_to_log.to_s
decorated_method.to_s
end
"#{klass_string}#{separator}#{method_string}"
end
Expand All @@ -69,7 +69,7 @@ def debug_signature_to_s(args: nil, kwargs: nil, config_proxy: nil) # rubocop:di

add_args_ellipsis = false
args = args.dup
args.push(kwargs) if kwargs
args.push(kwargs) if kwargs&.keys && !kwargs&.keys&.length&.zero?
if config_proxy.debug_last_hash_to_s_proc && args[-1].is_a?(Hash)
add_other_args_ellipsis = false
if args.length > 1
Expand Down Expand Up @@ -204,8 +204,8 @@ def debug_payload_to_s(payload: nil, config_proxy: nil)

module_function

def debug_event_name_to_s(method_to_notify: nil)
"#{method_to_notify}.log"
def debug_event_name_to_s(decorated_method: nil)
"#{decorated_method}.log"
end
end
end
Loading
Loading