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
52
53
|
describe("log module", function()
before_each(function()
local succ, log= pcall(require,"log")
if succ then log.reset() end
end)
it("should load",function()
require("log")
end)
it("should ingest a log",function()
local log = require("log")
log.log("test",nil,"blah")
end)
it("should return ingested logs from levels",function()
local log = require("log")
local ret = {}
log.log("test",nil,"blah")
log.of_level("blah",function(msg)
table.insert(ret, msg)
end)
assert(#ret == 1)
assert(ret[1].message == "test")
end)
it("should return ingested logs from tags", function()
local log = require("log")
local ret = {}
log.info("one",{"one"})
log.info("two",{"two"})
log.info("one two",{"one","two"})
log.of_tags({"one"},function(msg)
table.insert(ret,msg)
end)
assert(#ret == 2)
assert(ret[1].message == "one")
assert(ret[2].message == "one two")
end)
it("should allow observers to see the message stream", function()
local log = require("log")
local ret = {}
log.observe(function(chunk)
if chunk.level == "panic" then
table.insert(ret,chunk)
end
end)
log.info("one")
log.info("two")
assert(#ret == 0)
log.panic("three")
assert(#ret == 1)
log.info("four")
assert(#ret == 1)
assert(ret[1].message == "three")
end)
end)
|