Skip to content

Commit

Permalink
[logging] support for ActiveSupport::BroadcastLogger logger instances (
Browse files Browse the repository at this point in the history
  • Loading branch information
0exp authored Dec 10, 2024
1 parent c90b64a commit 0d82c68
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 13 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## [Unreleased]
### Changed
- Updated development dependencies (`armitage-rubocop`);
- Updated development dependencies (`armitage-rubocop`, `rbs`, `steep`);
- CI is splitted to "mainstream ruby version" and "previous actually maintaned ruby versions";
- `Acquier` -> `Acquirer`, `Acquierment` -> `Acquirement` (typos):
- [**Breaking**] Constant renaming: all constants and constant parts were renamed from `Acquier` to `Acquirer`;
Expand All @@ -17,6 +17,7 @@
- Added `TypeCheck` CI/CD step;
- Test coverage (via `simplecov` with `html` and `lcov` formats). `minimum_coverage` config is temporary disabled (and the CI step is not configured yet) cuz we need to refactor tests in first;
- CI: `rspec-retry` is temporary added until the tests are fully refactored;
- Support for `ActiveSupport::BroadcastLogger` logger instances;

## [1.12.1]
### Changed
Expand Down
12 changes: 6 additions & 6 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ GEM
fileutils (1.7.3)
i18n (1.14.6)
concurrent-ruby (~> 1.0)
json (2.8.2)
json (2.9.0)
language_server-protocol (3.17.0.3)
listen (3.9.0)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
logger (1.6.2)
method_source (1.1.0)
minitest (5.25.2)
minitest (5.25.4)
parallel (1.26.3)
parser (3.3.6.0)
ast (~> 2.4.1)
Expand All @@ -78,7 +78,7 @@ GEM
rb-fsevent (0.11.2)
rb-inotify (0.11.1)
ffi (~> 1.0)
rbs (3.6.1)
rbs (3.7.0)
logger
redis-client (0.22.2)
connection_pool
Expand All @@ -97,7 +97,7 @@ GEM
rspec-support (~> 3.13.0)
rspec-retry (0.6.2)
rspec-core (> 3.3)
rspec-support (3.13.1)
rspec-support (3.13.2)
rubocop (1.68.0)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
Expand Down Expand Up @@ -138,7 +138,7 @@ GEM
simplecov-html (0.13.1)
simplecov-lcov (0.8.0)
simplecov_json_formatter (0.1.4)
steep (1.8.3)
steep (1.9.1)
activesupport (>= 5.1)
concurrent-ruby (>= 1.1.10)
csv (>= 3.0.9)
Expand All @@ -149,7 +149,7 @@ GEM
logger (>= 1.3.0)
parser (>= 3.1)
rainbow (>= 2.2.2, < 4.0)
rbs (~> 3.6.0)
rbs (~> 3.7.0)
securerandom (>= 0.1)
strscan (>= 1.0.0)
terminal-table (>= 2, < 4)
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2105,7 +2105,6 @@ Detalized event semantics and payload structure:
- TypeChecking: (rbs) type signature testing (`RUBYOPT='-rrbs/test/setup' bundle exec rspec`);
- TypeChecking: (steep) 100%-typed calls (`steep stats` in CI);
- `unlock_on:`-option in lock/lock! logic in order to suppoert auto-unlocking on any exception rasaied under the invoked block (invoked under the lock);
- `Rails/ActiveSupport/Logging`: support for `ActiveSupport::BroadcastLogger` logger instances in `SemanticLogger` manner (vendor dependency with customized `debug`-method signature (`[[:rest, :*], [:keyrest, :**], [:block, :&]]`));
---
Expand Down
12 changes: 7 additions & 5 deletions lib/redis_queued_locks/logging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,14 @@ def valid_interface?(logger)

# NOTE:
# - convinient/conventional way to support the popular `semantic_logger` library
# - see https://logger.rocketjob.io/
# - see https://github.com/reidmorrison/semantic_logger

# steep:ignore:start
# - see https://logger.rocketjob.io/
# - see https://github.com/reidmorrison/semantic_logger
# - convinient/conventional way to support the popular `broadcast` RoR's logger;
# - see https://api.rubyonrails.org/classes/ActiveSupport/BroadcastLogger.html
# rubocop:disable Layout/LineLength
return true if defined?(::SemanticLogger::Logger) && logger.is_a?(::SemanticLogger::Logger)
# steep:ignore:end
return true if defined?(::ActiveSupport::BroadcastLogger) && logger.is_a?(::ActiveSupport::BroadcastLogger)
# rubocop:enable Layout/LineLength

# NOTE: should provide `#debug` method.
return false unless logger.respond_to?(:debug)
Expand Down
4 changes: 4 additions & 0 deletions sig/vendor/active_support.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@ module ActiveSupport
module Notifications
def self.instrument: (String event, Hash[untyped,untyped] payload) -> untyped
end

class BroadcastLogger
def debug: (*untyped, **untyped) { (?) -> untyped } -> untyped
end
end

0 comments on commit 0d82c68

Please sign in to comment.