41 lines
859 B
Lua
41 lines
859 B
Lua
local _M = { }
|
|
|
|
local log_levels = {
|
|
crit = "logCritical",
|
|
error = "logErr",
|
|
warn = "logWarn",
|
|
notice = "logTrace",
|
|
info = "logInfo",
|
|
debug = "logDebug",
|
|
}
|
|
|
|
local _tostring = tostring
|
|
local tostring = function(...)
|
|
local t = {}
|
|
for i = 1, select('#', ...) do
|
|
local x = select(i, ...)
|
|
if type(x) == "number" then
|
|
x = round(x, .01)
|
|
end
|
|
t[#t + 1] = _tostring(x)
|
|
end
|
|
return table.concat(t, " ")
|
|
end
|
|
|
|
function _M.new(handle)
|
|
local o = {}
|
|
setmetatable(o, {__index = function(self, cmd)
|
|
local t = getmetatable(handle)
|
|
local method = rawget(t, log_levels[cmd])
|
|
if not method then
|
|
return do_nothing
|
|
end
|
|
|
|
return function(...)
|
|
method(handle, tostring(...))
|
|
end
|
|
end})
|
|
return o
|
|
end
|
|
|
|
return _M |