Sha256: aae6ddab0b3335b3bc2ede035c1f8a5643bde67d13ee210f2c32f35476dc0940
Contents?: true
Size: 1.89 KB
Versions: 10
Compression:
Stored size: 1.89 KB
Contents
require "spec_helper" describe Pliny::Log do before do @io = StringIO.new Pliny.stdout = @io stub(@io).print end after do Pliny.default_context = {} end it "logs in structured format" do mock(@io).print "foo=bar baz=42\n" Pliny.log(foo: "bar", baz: 42) end it "re-raises errors" do assert_raises(RuntimeError) do Pliny.log(foo: "bar") do raise RuntimeError end end end it "supports blocks to log stages and elapsed" do mock(@io).print "foo=bar at=start\n" mock(@io).print "foo=bar at=finish elapsed=0.000\n" Pliny.log(foo: "bar") do end end it "merges default context" do Pliny.default_context = { app: "pliny" } mock(@io).print "app=pliny foo=bar\n" Pliny.log(foo: "bar") end it "merges context from RequestStore" do Pliny::RequestStore.store[:log_context] = { app: "pliny" } mock(@io).print "app=pliny foo=bar\n" Pliny.log(foo: "bar") end it "supports a context" do mock(@io).print "app=pliny foo=bar\n" Pliny.context(app: "pliny") do Pliny.log(foo: "bar") end end it "local context does not overwrite default context" do Pliny.default_context = { app: "pliny" } mock(@io).print "app=not_pliny foo=bar\n" Pliny.log(app: 'not_pliny', foo: "bar") assert Pliny.default_context[:app] == "pliny" end it "local context does not overwrite request context" do Pliny::RequestStore.store[:log_context] = { app: "pliny" } mock(@io).print "app=not_pliny foo=bar\n" Pliny.context(app: "not_pliny") do Pliny.log(foo: "bar") end assert Pliny::RequestStore.store[:log_context][:app] == "pliny" end it "local context does not propagate outside" do Pliny::RequestStore.store[:log_context] = { app: "pliny" } mock(@io).print "app=pliny foo=bar\n" Pliny.context(app: "not_pliny", test: 123) do end Pliny.log(foo: "bar") end end
Version data entries
10 entries across 10 versions & 1 rubygems