-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlog.lua
More file actions
51 lines (45 loc) · 1.29 KB
/
Copy pathlog.lua
File metadata and controls
51 lines (45 loc) · 1.29 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
local nc = require("common.new_class")
local matching = nil
local general_priority = 0
local Logger = nc.new_class({})
function Logger.new(namespace)
--- @class Logger
--- @field namespace string
--- @field debug fun(...)
--- @field info fun(...)
--- @field warn fun(...)
--- @field error fun(...)
--- @field trace fun(...)
local self = setmetatable({ namespace = namespace, loglevel = 1 }, Logger)
self.__index = self
return self
end
function Logger:_meta(metaname)
local priority = general_priority
general_priority = general_priority + 1
self[metaname] = function(this, ...)
-- if matching == nil then
if priority >= this.loglevel then
local namespace = this.namespace and (this.namespace) or ""
print(string.format("%s[%s] ", namespace, metaname), ...)
end
-- elseif matching ~= nil then
-- --TODO: add string matching and level filter
-- assert(false, "not implemented")
-- end
end
end
Logger:_meta("trace")
Logger:_meta("info")
Logger:_meta("debug")
Logger:_meta("warn")
Logger:_meta("error")
---@type Logger
local M = Logger()
---Creates a logger at module level
---@param name string
---@return Logger
function M.module(name)
return Logger(name)
end
return M