-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogging.lua
More file actions
82 lines (65 loc) · 1.38 KB
/
logging.lua
File metadata and controls
82 lines (65 loc) · 1.38 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
Logger = {
}
function Logger:new (o, source_config)
o = o or {}
setmetatable(o, self)
self.__index = self
self.source = source_config or {}
self.source.chip_id = node.chipid()
return o
end
function Logger:_log(priority, msg)
event = {
source = self.source,
priority = priority,
message = msg
}
print(cjson.encode(event))
-- mqtt(event)
end
function Logger:debug(msg)
self:_log("debug", msg)
end
function Logger:info(msg)
self:_log("info", msg)
end
function Logger:notice(msg)
self:_log("notice", msg)
end
function Logger:warn(msg)
self:_log("warn", msg)
end
function Logger:crit(msg)
self:_log("crit", msg)
end
function Logger:emerg(msg)
self:_log("emerg", msg)
end
Module = {
log = Logger:new(nil, { process = "test-module" } )
}
function Module:new (o, name)
o = o or {}
setmetatable(o, self)
self.__index = self
self.name = name
self.log.process_name = name
return o
end
function Module:test(blah)
self.log:debug(blah)
self.log:info(blah)
self.log:notice(blah)
self.log:warn(blah)
self.log:crit(blah)
self.log:emerg(blah)
end
Trigger = {}
-- filter: function that returns a boolean. true to exec callback
function Trigger:onMessage( filter, callback )
end
-- can schedule be a cron type string? exec callback when match
function Trigger:onSchedule( schedule, callback )
end
m = Module:new(nil, "test-module")
m:test("asdasd")