Comparison

init.lua @ 142:ea753bc81a33

verse: Add verse.filter_log(levels, logger) to filter a logger for certain levels
author Matthew Wild <mwild1@gmail.com>
date Wed, 15 Sep 2010 16:52:18 +0100
parent 141:15706f6492ae
child 162:2950079d4319
comparison
equal deleted inserted replaced
141:15706f6492ae 142:ea753bc81a33
31 verse.log = verse.logger("verse"); 31 verse.log = verse.logger("verse");
32 32
33 function verse.set_logger(logger) 33 function verse.set_logger(logger)
34 verse.log = logger; 34 verse.log = logger;
35 server.setlogger(logger); 35 server.setlogger(logger);
36 end
37
38 function verse.filter_log(levels, logger)
39 local level_set = {};
40 for _, level in ipairs(levels) do
41 level_set[level] = true;
42 end
43 return function (level, name, ...)
44 if level_set[level] then
45 return logger(level, name, ...);
46 end
47 end;
36 end 48 end
37 49
38 local function error_handler(err) 50 local function error_handler(err)
39 verse.log("error", "Error: %s", err); 51 verse.log("error", "Error: %s", err);
40 verse.log("error", "Traceback: %s", debug.traceback()); 52 verse.log("error", "Traceback: %s", debug.traceback());