forked from interagent/pliny
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog_spec.rb
51 lines (44 loc) · 1.3 KB
/
log_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
require "spec_helper"
describe Pliny::Log do
before do
@io = StringIO.new
Pliny.stdout = @io
stub(@io).print
end
it "logs in structured format" do
mock(@io).print "foo=bar baz=42\n"
Pliny.log(foo: "bar", baz: 42)
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 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 global" 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