4 -- Written by Timm S. Mueller <tmueller at neoscientists.org>
5 -- See copyright notice in COPYRIGHT
8 local getinfo = require "debug".getinfo
9 local date = require "os".date
10 local stderr = require "io".stderr
11 local tostring = tostring
18 module "tek.lib.debug"
20 level = 10 -- global default
22 function print(lvl, msg, ...)
23 if level and lvl >= level then
24 local t = getinfo(3, "lS")
25 -- stderr:write(("(%02d %d %s:%d) "):format(lvl,
26 -- time(), t.short_src, t.currentline))
28 for i = 1, select('#', ...) do
29 local v = select(i, ...)
33 arg[i] = type(v) ~= "number" and tostring(v) or v
36 stderr:write(("(%02d %d %s:%d) " .. msg):format(lvl, time(), t.short_src, t.currentline, unpack(arg)) .. "\n")
40 function execute(lvl, func, ...)
41 if level and lvl >= level then
46 function trace(msg, ...) print(2, msg, ...) end
47 function note(msg, ...) print(3, msg, ...) end
48 function info(msg, ...) print(4, msg, ...) end
49 function warn(msg, ...) print(5, msg, ...) end
50 function error(msg, ...) print(10, msg, ...) end
51 function fail(msg, ...) print(20, msg, ...) end
53 function dotrace(msg, ...) execute(2, msg, ...) end
54 function donote(msg, ...) execute(3, msg, ...) end
55 function doinfo(msg, ...) execute(4, msg, ...) end
56 function dowarn(msg, ...) execute(5, msg, ...) end
57 function doerror(msg, ...) execute(10, msg, ...) end
58 function dofail(msg, ...) execute(20, msg, ...) end