Software /
code /
verse
Comparison
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 |
comparison
equal
deleted
inserted
replaced
278:6f58f6f3986d | 279:7a0aa3d055f4 |
---|---|
55 end | 55 end |
56 | 56 |
57 function verse.set_log_handler(log_handler, levels) | 57 function verse.set_log_handler(log_handler, levels) |
58 levels = levels or { "debug", "info", "warn", "error" }; | 58 levels = levels or { "debug", "info", "warn", "error" }; |
59 logger.reset(); | 59 logger.reset(); |
60 local function _log_handler(name, level, message, ...) | 60 if io.type(log_handler) == "file" then |
61 return log_handler(name, level, format(message, ...)); | 61 local f = log_handler; |
62 function log_handler(name, level, message) | |
63 f:write(name, "\t", level, "\t", message, "\n"); | |
64 end | |
62 end | 65 end |
63 if log_handler then | 66 if log_handler then |
67 local function _log_handler(name, level, message, ...) | |
68 return log_handler(name, level, format(message, ...)); | |
69 end | |
64 for i, level in ipairs(levels) do | 70 for i, level in ipairs(levels) do |
65 logger.add_level_sink(level, _log_handler); | 71 logger.add_level_sink(level, _log_handler); |
66 end | 72 end |
67 end | 73 end |
68 end | 74 end |