util/logger.lua
author Matthew Wild <mwild1@gmail.com>
Wed, 01 May 2013 13:54:00 +0100
branchs2s
changeset 5558 774ab5f2efa6
parent 147 ccebb2720741
child 259 1485d272400d
permissions -rw-r--r--
Close 's2s' branch


local format = string.format;
local print = print;
local debug = debug;
local tostring = tostring;
module "logger"

function init(name)
	--name = nil; -- While this line is not commented, will automatically fill in file/line number info
	return 	function (level, message, ...)
				if not name then
					local inf = debug.getinfo(3, 'Snl');
					level = level .. ","..tostring(inf.short_src):match("[^/]*$")..":"..inf.currentline;
				end
				if ... then 
					print(level, format(message, ...));
				else
					print(level, message);
				end
			end
end

return _M;