libs/logger.lua

changeset 238
9b6fca5d9a02
parent 237
d158c97556b4
child 239
65a0d3fcbbad
equal deleted inserted replaced
237:d158c97556b4 238:9b6fca5d9a02
1 local select, tostring = select, tostring;
2 local io_write = io.write;
3 module "logger"
4
5 local function format(format, ...)
6 local n, maxn = 0, #arg;
7 return (format:gsub("%%(.)", function (c) if c ~= "%" and n <= maxn then n = n + 1; return tostring(arg[n]); end end));
8 end
9
10 local function format(format, ...)
11 local n, maxn = 0, select('#', ...);
12 local arg = { ... };
13 return (format:gsub("%%(.)", function (c) if n <= maxn then n = n + 1; return tostring(arg[n]); end end));
14 end
15
16 function init(name)
17 return function (level, message, ...)
18 io_write(level, "\t", format(message, ...), "\n");
19 end
20 end
21
22 return _M;

mercurial