Software /
code /
verse
File
libs/logger.lua @ 125:b46921de1e03
verse: Add verse.log() to log a message using the default logger. Also add verse.set_error_handler() to, er, set an error handler.
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Mon, 13 Sep 2010 14:07:41 +0100 (2010-09-13) |
parent | 5:93970910d064 |
child | 127:8f831f259cea |
line wrap: on
line source
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;