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
     1 
     2 --
     3 --	tek.lib.debug
     4 --	Written by Timm S. Mueller <tmueller at neoscientists.org>
     5 --	See copyright notice in COPYRIGHT
     6 --
     7 
     8 local getinfo = require "debug".getinfo
     9 local date = require "os".date
    10 local stderr = require "io".stderr
    11 local tostring = tostring
    12 local ipairs = ipairs
    13 local type = type
    14 local unpack = unpack
    15 
    16 module "tek.lib.debug"
    17 
    18 level = 10 -- global default
    19 
    20 function print(lvl, msg, ...)
    21 	if level and lvl >= level then
    22 		local t = getinfo(3, "lS")
    23 		local arg = { }
    24 		for i, v in ipairs { ... } do
    25 			arg[i] = type(v) == "table" and tostring(v) or v
    26 		end
    27 		stderr:write(("(%02d %s:%d) %s\n"):format(lvl,
    28 			t.short_src, t.currentline, msg:format(unpack(arg))))
    29 	end
    30 end
    31 
    32 function debug(msg, ...)
    33 	print(1, msg, ...)
    34 end
    35 
    36 function trace(msg, ...)
    37 	print(2, msg, ...)
    38 end
    39 
    40 function info(msg, ...)
    41 	print(4, msg, ...)
    42 end
    43 
    44 function warn(msg, ...)
    45 	print(5, msg, ...)
    46 end
    47 
    48 function error(msg, ...)
    49 	print(10, msg, ...)
    50 end
    51 
    52 function fail(msg, ...)
    53 	print(20, msg, ...)
    54 end