File

libs/logger.lua @ 201:1fce24cb2c41

plugins.smacks: Remove some debugging code from resumption success handling, and fire a "resumed" event instead
author Matthew Wild <mwild1@gmail.com>
date Fri, 18 Mar 2011 21:42:49 +0000
parent 127:8f831f259cea
line wrap: on
line source

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;