Skip to content

Commit

Permalink
Expand tests for progname handling
Browse files Browse the repository at this point in the history
  • Loading branch information
timriley committed May 10, 2024
1 parent 4b4f569 commit f327a7f
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions spec/dry/logger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,42 @@
end
end

context "using progname" do
subject(:logger) { Dry.Logger(:test, stream: stream, template: "%<progname>s: %<message>s %<payload>s") }

it "uses the logger ID as the progname" do
message = "hello, world"

logger.info(message)

expect(output).to match("test: #{message}")
end

it "replaces the default progname with the progname: keyword argument" do
message = "hello, world"

logger.info(message, progname: "newprog", test: true)

expect(output).to match("newprog: #{message} test=true")
end

it "replaces the progname with the first string argument when the message is given as a block" do
message = "hello, world"

logger.info("newprog") { message }

expect(output).to match("newprog: hello, world")
end

it "replaces the progname with the progname: keyword argument when the message is given as a block" do
message = "hello, world"

logger.info(progname: "newprog", test: true) { message }

expect(output).to match("newprog: #{message} test=true")
end
end

context "adding backends via block only" do
it "doesn't setup the default logger" do
logger = Dry.Logger(:test, stream: stream) { |setup|
Expand Down

0 comments on commit f327a7f

Please sign in to comment.