Software /
code /
verse
Diff
init.lua @ 279:7a0aa3d055f4
verse: Accept a file object as a log handler, and automatically call :write() on it with a formatted message
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sun, 12 Feb 2012 20:21:52 +0000 |
parent | 259:05acf08d2e98 |
child | 280:981c8867f1fb |
line wrap: on
line diff
--- a/init.lua Sun Feb 12 02:27:56 2012 +0100 +++ b/init.lua Sun Feb 12 20:21:52 2012 +0000 @@ -57,10 +57,16 @@ function verse.set_log_handler(log_handler, levels) levels = levels or { "debug", "info", "warn", "error" }; logger.reset(); - local function _log_handler(name, level, message, ...) - return log_handler(name, level, format(message, ...)); + if io.type(log_handler) == "file" then + local f = log_handler; + function log_handler(name, level, message) + f:write(name, "\t", level, "\t", message, "\n"); + end end if log_handler then + local function _log_handler(name, level, message, ...) + return log_handler(name, level, format(message, ...)); + end for i, level in ipairs(levels) do logger.add_level_sink(level, _log_handler); end