cgi-bin/tek/lib/debug.lua
changeset 201 d52b05a9fe9c
child 205 4b7e44d9cc88
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/cgi-bin/tek/lib/debug.lua	Fri Nov 23 01:46:43 2007 +0100
     1.3 @@ -0,0 +1,54 @@
     1.4 +
     1.5 +--
     1.6 +--	tek.lib.debug
     1.7 +--	Written by Timm S. Mueller <tmueller at neoscientists.org>
     1.8 +--	See copyright notice in COPYRIGHT
     1.9 +--
    1.10 +
    1.11 +local getinfo = require "debug".getinfo
    1.12 +local date = require "os".date
    1.13 +local stderr = require "io".stderr
    1.14 +local tostring = tostring
    1.15 +local ipairs = ipairs
    1.16 +local type = type
    1.17 +local unpack = unpack
    1.18 +
    1.19 +module "tek.lib.debug"
    1.20 +
    1.21 +level = 10 -- global default
    1.22 +
    1.23 +function print(lvl, msg, ...)
    1.24 +	if level and lvl >= level then
    1.25 +		local t = getinfo(3, "lS")
    1.26 +		local arg = { }
    1.27 +		for i, v in ipairs { ... } do
    1.28 +			arg[i] = type(v) == "table" and tostring(v) or v
    1.29 +		end
    1.30 +		stderr:write(("(%02d %s:%d) %s\n"):format(lvl,
    1.31 +			t.short_src, t.currentline, msg:format(unpack(arg))))
    1.32 +	end
    1.33 +end
    1.34 +
    1.35 +function debug(msg, ...)
    1.36 +	print(1, msg, ...)
    1.37 +end
    1.38 +
    1.39 +function trace(msg, ...)
    1.40 +	print(2, msg, ...)
    1.41 +end
    1.42 +
    1.43 +function info(msg, ...)
    1.44 +	print(4, msg, ...)
    1.45 +end
    1.46 +
    1.47 +function warn(msg, ...)
    1.48 +	print(5, msg, ...)
    1.49 +end
    1.50 +
    1.51 +function error(msg, ...)
    1.52 +	print(10, msg, ...)
    1.53 +end
    1.54 +
    1.55 +function fail(msg, ...)
    1.56 +	print(20, msg, ...)
    1.57 +end