More robust debugging facilities
authorTimm S. Mueller <tmueller@neoscientists.org>
Sat, 24 Nov 2007 20:47:22 +0100
changeset 2054b7e44d9cc88
parent 204 df7e8b0dfa56
child 206 450cd443de9f
More robust debugging facilities
cgi-bin/tek/lib/debug.lua
     1.1 --- a/cgi-bin/tek/lib/debug.lua	Sat Nov 24 20:46:59 2007 +0100
     1.2 +++ b/cgi-bin/tek/lib/debug.lua	Sat Nov 24 20:47:22 2007 +0100
     1.3 @@ -12,6 +12,8 @@
     1.4  local ipairs = ipairs
     1.5  local type = type
     1.6  local unpack = unpack
     1.7 +local select = select
     1.8 +local time = os.time
     1.9  
    1.10  module "tek.lib.debug"
    1.11  
    1.12 @@ -20,35 +22,37 @@
    1.13  function print(lvl, msg, ...)
    1.14  	if level and lvl >= level then
    1.15  		local t = getinfo(3, "lS")
    1.16 +-- 		stderr:write(("(%02d %d %s:%d) "):format(lvl,
    1.17 +-- 			time(), t.short_src, t.currentline))
    1.18  		local arg = { }
    1.19 -		for i, v in ipairs { ... } do
    1.20 -			arg[i] = type(v) == "table" and tostring(v) or v
    1.21 +		for i = 1, select('#', ...) do
    1.22 +			local v = select(i, ...)
    1.23 +			if not v then
    1.24 +				arg[i] = 0
    1.25 +			else
    1.26 +				arg[i] = type(v) ~= "number" and tostring(v) or v
    1.27 +			end
    1.28  		end
    1.29 -		stderr:write(("(%02d %s:%d) %s\n"):format(lvl,
    1.30 -			t.short_src, t.currentline, msg:format(unpack(arg))))
    1.31 +		stderr:write(("(%02d %d %s:%d) " .. msg):format(lvl, time(), t.short_src, t.currentline, unpack(arg)) .. "\n")
    1.32  	end
    1.33  end
    1.34  
    1.35 -function debug(msg, ...)
    1.36 -	print(1, msg, ...)
    1.37 +function execute(lvl, func, ...)
    1.38 +	if level and lvl >= level then
    1.39 +		func(...)
    1.40 +	end
    1.41  end
    1.42  
    1.43 -function trace(msg, ...)
    1.44 -	print(2, msg, ...)
    1.45 -end
    1.46 +function trace(msg, ...) print(2, msg, ...) end
    1.47 +function note(msg, ...) print(3, msg, ...) end
    1.48 +function info(msg, ...) print(4, msg, ...) end
    1.49 +function warn(msg, ...) print(5, msg, ...) end
    1.50 +function error(msg, ...) print(10, msg, ...) end
    1.51 +function fail(msg, ...) print(20, msg, ...) end
    1.52  
    1.53 -function info(msg, ...)
    1.54 -	print(4, msg, ...)
    1.55 -end
    1.56 -
    1.57 -function warn(msg, ...)
    1.58 -	print(5, msg, ...)
    1.59 -end
    1.60 -
    1.61 -function error(msg, ...)
    1.62 -	print(10, msg, ...)
    1.63 -end
    1.64 -
    1.65 -function fail(msg, ...)
    1.66 -	print(20, msg, ...)
    1.67 -end
    1.68 +function dotrace(msg, ...) execute(2, msg, ...) end
    1.69 +function donote(msg, ...) execute(3, msg, ...) end
    1.70 +function doinfo(msg, ...) execute(4, msg, ...) end
    1.71 +function dowarn(msg, ...) execute(5, msg, ...) end
    1.72 +function doerror(msg, ...) execute(10, msg, ...) end
    1.73 +function dofail(msg, ...) execute(20, msg, ...) end