cgi-bin/tek/lib/debug.lua
author Timm S. Mueller <tmueller@neoscientists.org>
Fri, 23 Nov 2007 01:46:43 +0100
changeset 201 d52b05a9fe9c
child 205 4b7e44d9cc88
permissions -rw-r--r--
Added permission for lua.cgi in Makefile; FastCGI class added; improved
configuration and statistics output in FastCGI runner; versionstring format
changed; inheritance is now based on tek.class - Atom class removed; Debug
library added; removed "attr" permission
tmueller@201
     1
tmueller@201
     2
--
tmueller@201
     3
--	tek.lib.debug
tmueller@201
     4
--	Written by Timm S. Mueller <tmueller at neoscientists.org>
tmueller@201
     5
--	See copyright notice in COPYRIGHT
tmueller@201
     6
--
tmueller@201
     7
tmueller@201
     8
local getinfo = require "debug".getinfo
tmueller@201
     9
local date = require "os".date
tmueller@201
    10
local stderr = require "io".stderr
tmueller@201
    11
local tostring = tostring
tmueller@201
    12
local ipairs = ipairs
tmueller@201
    13
local type = type
tmueller@201
    14
local unpack = unpack
tmueller@201
    15
tmueller@201
    16
module "tek.lib.debug"
tmueller@201
    17
tmueller@201
    18
level = 10 -- global default
tmueller@201
    19
tmueller@201
    20
function print(lvl, msg, ...)
tmueller@201
    21
	if level and lvl >= level then
tmueller@201
    22
		local t = getinfo(3, "lS")
tmueller@201
    23
		local arg = { }
tmueller@201
    24
		for i, v in ipairs { ... } do
tmueller@201
    25
			arg[i] = type(v) == "table" and tostring(v) or v
tmueller@201
    26
		end
tmueller@201
    27
		stderr:write(("(%02d %s:%d) %s\n"):format(lvl,
tmueller@201
    28
			t.short_src, t.currentline, msg:format(unpack(arg))))
tmueller@201
    29
	end
tmueller@201
    30
end
tmueller@201
    31
tmueller@201
    32
function debug(msg, ...)
tmueller@201
    33
	print(1, msg, ...)
tmueller@201
    34
end
tmueller@201
    35
tmueller@201
    36
function trace(msg, ...)
tmueller@201
    37
	print(2, msg, ...)
tmueller@201
    38
end
tmueller@201
    39
tmueller@201
    40
function info(msg, ...)
tmueller@201
    41
	print(4, msg, ...)
tmueller@201
    42
end
tmueller@201
    43
tmueller@201
    44
function warn(msg, ...)
tmueller@201
    45
	print(5, msg, ...)
tmueller@201
    46
end
tmueller@201
    47
tmueller@201
    48
function error(msg, ...)
tmueller@201
    49
	print(10, msg, ...)
tmueller@201
    50
end
tmueller@201
    51
tmueller@201
    52
function fail(msg, ...)
tmueller@201
    53
	print(20, msg, ...)
tmueller@201
    54
end