libs/logger.lua

Sun, 05 Dec 2010 01:06:29 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Sun, 05 Dec 2010 01:06:29 +0000
changeset 160
5cbbfe42212e
parent 127
8f831f259cea
permissions
-rw-r--r--

plugins.bind: Fix the bind-success event, now fires with data { jid = result_jid } (thanks Jon)

local select, tostring = select, tostring;
local io_write = io.write;
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, ...)
		io_write(level, "\t", format(message, ...), "\n");
	end
end

return _M;

mercurial