libs/logger.lua

Sat, 28 Nov 2009 22:28:03 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Sat, 28 Nov 2009 22:28:03 +0000
changeset 10
3a422606a040
parent 5
93970910d064
child 127
8f831f259cea
permissions
-rw-r--r--

verse.client: Fire events on stream features, errors, etc. and on non-stream tags such as SASL and TLS

local print = print
local select, tostring = select, tostring;
module "logger"

local function format(format, ...)
	local n, maxn = 0, #arg;
	return (format:gsub("%%(.)", function (c) if c ~= "%" and n <= maxn then n = n + 1; return tostring(arg[n]); end end));
end

local function format(format, ...)
	local n, maxn = 0, select('#', ...);
	local arg = { ... };
	return (format:gsub("%%(.)", function (c) if n <= maxn then n = n + 1; return tostring(arg[n]); end end));
end

function init(name)
	return function (level, message, ...)
		print(level, format(message, ...));
	end
end

return _M;

mercurial