Skip to content

Commit c57db06

Browse files
authored
Merge branch 'main' into feature/dont-execute-block-if-severity-less-than-level
2 parents 7691e0c + 7df27f8 commit c57db06

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

.github/workflows/ci.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ jobs:
2424

2525
- 3.3
2626

27+
- 3.3.0
28+
2729
- 3.2
2830

2931
- 3.1
@@ -45,6 +47,13 @@ jobs:
4547
bundler-cache: true
4648
- name: Run all tests
4749
run: bundle exec rake
50+
workflow-keepalive:
51+
if: github.event_name == 'schedule'
52+
runs-on: ubuntu-latest
53+
permissions:
54+
actions: write
55+
steps:
56+
- uses: liskin/gh-workflow-keepalive@v1
4857
release:
4958
runs-on: ubuntu-latest
5059
if: contains(github.ref, 'tags') && github.event_name == 'create'

dry-logger.gemspec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ Gem::Specification.new do |spec|
2121
spec.executables = []
2222
spec.require_paths = ["lib"]
2323

24+
spec.extra_rdoc_files = ["README.md", "CHANGELOG.md", "LICENSE"]
25+
2426
spec.metadata["allowed_push_host"] = "https://rubygems.org"
2527
spec.metadata["changelog_uri"] = "https://github.com/dry-rb/dry-logger/blob/main/CHANGELOG.md"
2628
spec.metadata["source_code_uri"] = "https://github.com/dry-rb/dry-logger"
@@ -32,6 +34,5 @@ Gem::Specification.new do |spec|
3234
spec.add_development_dependency "bundler"
3335
spec.add_development_dependency "rake"
3436
spec.add_development_dependency "rspec"
35-
3637
end
3738

lib/dry/logger/dispatcher.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,12 @@ def log(severity, message = nil, **payload, &block)
213213
else
214214
if block
215215
progname = message
216-
message = block.call
216+
block_result = block.call
217+
case block_result
218+
when Hash then payload = block_result
219+
else
220+
message = block_result
221+
end
217222
end
218223
progname ||= id
219224

spec/dry/logger_spec.rb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,30 @@
3434
expect(output).to match(message)
3535
end
3636

37+
it "logs to $stdout by default using a payload block" do
38+
logger.info { {test: true} }
39+
40+
expect(output).to match("test=true")
41+
end
42+
3743
it "logs to $stdout by default using a plain text block message and payload" do
3844
message = "hello, world"
3945

4046
logger.info(test: true) { message }
4147

4248
expect(output).to match("#{message} test=true")
4349
end
50+
51+
it "logs to $stdout by default using a plain text message and payload block" do
52+
message = "hello, world"
53+
54+
logger.info(message) { {test: true} }
55+
56+
expect(output).to match("#{message} test=true")
57+
end
4458

4559
it "does not execute the block if severity is higher" do
46-
logger.debug { raise }
60+
logger.debug { raise }
4761
end
4862
end
4963

0 commit comments

Comments
 (0)