Changeset

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
parents 278:6f58f6f3986d
children 280:981c8867f1fb 282:52b971d9ebc3
files init.lua
diffstat 1 files changed, 8 insertions(+), 2 deletions(-) [+]
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